不一定要用数据源,查询也可以用。
比如我的这个模块:
Option Compare Database
Option Explicit
Function TextboxRefresh()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim MyQuery As String
Set db = CurrentDb
MyQuery = "SELECT Sum(金额) AS 金额合计 FROM (SELECT Sum([订货详情].[数量]*[订货详情].[单价]) AS 金额 FROM 发票 INNER JOIN 订货详情 ON 发票.单号 = 订货详情.单号 GROUP BY 订货详情.单号, 发票.签单日期, 发票.barcode, 发票.客户ID, 发票.已收 HAVING (((发票.签单日期)=Date())));"
Set rst = db.OpenRecordset(MyQuery, dbOpenDynaset)