2017-06-07 48 views
0

請幫助解決此問題:「參數預期太少1」。從SQL到VBA的DLookup語句

的問題是在

If(IsNull([tblMaintWO]![Technian1]),'', DLookup('Initial', tblEmployees, 'EmpID=' & [tblMaintWO]![Technian1])) AS TechnianA

我不能把雙引號中陳述或者它會顯示一個紅色的句子,並引發錯誤。

strSQL = "SELECT tblMaintWO.MWONo, tblMaintWO.TaskOpenDate, tblMaintWO.MTRStation, tblMaintWO.Task, tblMaintWO.RequestedPriority, tblMaintWO.WorkOrderStatus, tblMaintWO.Technian1, " 
strSQL = strSQL & "IIf([CMFollowUp] = True, 'CM', IIf([PreventiveMaint] = True, 'PM', IIf([EIVO] = True, 'EI/VO', 'Other'))) AS TaskType, " 
strSQL = strSQL & "IIf(IsNull([tblMaintWO]![Technian1]),'', DLookup('Initial', tblEmployees, 'EmpID=' & [tblMaintWO]![Technian1])) AS TechnianA " 
strSQL = strSQL & "FROM tblMaintWO, tblEmployees;" 

回答

0

試試這個:

strSQL = "SELECT tblMaintWO.MWONo, tblMaintWO.TaskOpenDate, tblMaintWO.MTRStation, tblMaintWO.Task, tblMaintWO.RequestedPriority, tblMaintWO.WorkOrderStatus, tblMaintWO.Technian1, " 
strSQL = strSQL & "IIf([CMFollowUp] = True, 'CM', IIf([PreventiveMaint] = True, 'PM', IIf([EIVO] = True, 'EI/VO', 'Other'))) AS TaskType, " 
strSQL = strSQL & "IIf(IsNull([tblMaintWO]![Technian1]),'', DLookup('Initial', 'tblEmployees', 'EmpID=' & [tblMaintWO]![Technian1] & '')) AS TechnianA " 
strSQL = strSQL & "FROM tblMaintWO, tblEmployees;" 
+0

一切正常,謝謝! – Kosan

+0

太棒了!然後請標記爲已回答。 – Gustav