Below is the code. The strUpdateTo variable does get populated with the correct string, but I get an error stating "Data type mismatch in criteria expression."
Code: Select all
strSQL = "SELECT tlkpA_PayCode.Code " & _
"FROM tlkpA_PayCode " & _
"WHERE (((tlkpA_PayCode.[Include in OA?])='Y'));"
strUpdateTo = ""
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
testor = 0
Do While rst.EOF = False
testor = testor + 1
If testor > 1 Then
strUpdateTo = strUpdateTo & " +" & "[" & rst!code & "]"
Else
strUpdateTo = "[" & rst!code & "]"
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
strUpdateTo = Chr(34) & strUpdateTo & Chr(34)
' Loop through the lookup table to populate the UpdateTo section of the query
DoCmd.RunSQL "UPDATE tmpHoursOut SET tmpHoursOut.Total_Dist_Hour = IIf((" & strUpdateTo & ") >0," & strUpdateTo & ",0) ;"
Any ideas?