以下位代码放在表单的On Load
事件中:
Dim LAOQWeekdaySQL As String
Dim LAOQWeekday As QueryDef
Dim EnqIDTest As String
EnqIDTest = Me.txt_EnquiryID.Value
LAOQWeekdaySQL = "SELECT tbl_Costing_Labour.EnquiryID, tbl_Costing_Labour.PhaseLabour, tbl_Costing_Labour.TotalPhaseLabourHours " & _
"FROM tbl_Costing_Labour " & _
"WHERE (((tbl_Costing_Labour.EnquiryID)= " & EnqIDTest & ") AND ((tbl_Costing_Labour.PhaseLabour) Like ""*weekday*""));"
Set LAOQWeekday = CurrentDb.QueryDefs("LAOQWeekdayQRY").SQL = LAOQWeekdaySQL
Me.txt_LAOQ_Weekday.Value = DSum("TotalPhaseLabourHours", "LAOQWeekdayQRY")
基本上,它返回与查询号匹配的记录,并对查询中的最后一列求和,并将其输出到表单上的文本框。
然而,当我运行表单时,它给了我一个
编译错误:类型不匹配
在此之前,我确实尝试使用临时查询但是Dsum在执行其功能时没有要引用的名称,因此我将其更改为.CreateQueryDef
,这在第一次正常工作。此后,很明显,它抛出一个错误,说查询已经存在,所以我沿着.QueryDefs
的路线转而更新SQL而现在我得到了不匹配错误。
我看不到任何明显的东西,我在这里缺少什么?
提前感谢您提供任何帮助!
答案 0 :(得分:2)
以下行评估为布尔值:
Set LAOQWeekday = CurrentDb.QueryDefs("LAOQWeekdayQRY").SQL = LAOQWeekdaySQL
尝试将其更改为:
Set LAOQWeekday = CurrentDb.QueryDefs("LAOQWeekdayQRY")
LAOQWeekday.SQL = LAOQWeekdaySQL