Can someone tell me the syntax for using variables in a VBA update statement? I have the following that I want to use to update a record field.
I'm getting run-time error '3144' when the database tries to run the SQL. So I'm assuming my syntax is wrong (specifically in the WHERE clause)?
Code:
Dim thisTbl as String
If Answer = vbYes Then
If MedicationInvNo2 <> "" Then
thisTbl = "tblMyMedData"
Else
thisTbl = "tblMedData"
End If
If thisTbl = "tblMyMedData" Then
DoCmd.RunCommand acCmdUndo
Me.RecordSource = "tblMyMedData"
Me.Filter = "[InvNo] = '" & MedicationInvNo & "'"
Me.FilterOn = True
DoCmd.SetWarnings (False)
SQL = "UPDATE " & thisTbl & _
"SET Deleted = 0 " & _
"WHERE ((" & thisTbl & ".InvNo)) = (([Forms]![frmMedDataEntry]![InvNo])); "
Else
DoCmd.RunCommand acCmdUndo
Me.RecordSource = "tblMedData"
Me.Filter = "[InvNo] = '" & MedicationInvNo & "'"
Me.FilterOn = True
DoCmd.SetWarnings (False)
SQL = "UPDATE " & thisTbl & _
"SET Deleted = 0 " & _
"WHERE ((' & thisTbl & .InvNo' )) = (([Forms]![frmMedDataEntry]![InvNo])); "
End If
DoCmd.RunSQL SQL
DoCmd.SetWarnings (True)
End If
I'm getting run-time error '3144' when the database tries to run the SQL. So I'm assuming my syntax is wrong (specifically in the WHERE clause)?