Skip to content
Advertisement

Error messages with SQL commands SELECT and UPDATE in Access VBA

I am trying to update an Access table with the following code:

strSelectRec = "SELECT * FROM EmployeeDemographics WHERE (LastName) = ('" & strLast & "') AND (FirstName) = ('" & strFirst & "')"
strUpdateRec = "UPDATE EmployeeDemographics SET (Photo)= " & "('" & strPhoto & "')" & " WHERE (LastName)= " & "('" & strLast & "')" & " AND (FirstName)= " & "('" & strFirst & "')"

MsgBox (strSelectRec)
MsgBox (strUpdateRec)
DoCmd.RunSQL strSelectRec
DoCmd.RunSQL strUpdateRec

I have tried with and without parentheticals, tablename.fieldname, commenting out the select statement and run code.

The select code throws the error message:

Run-time Error ‘2342’ RUNSQL action requires an argument consisting of an SQL statement.

Without the select command, the update command throws:

Run-time error ‘3144’ Syntax error in Update statement.

What it is supposed to do is just take the path of the picture and update the photo field in the table based on the employee first and last name.

The message box shows the correct file path.

Advertisement

Answer

Tested your SQL. Doesn’t like parens around field names. Remove all parens and simplify concatenation.

strUpdateRec = "UPDATE EmployeeDemographics SET Photo='" & strPhoto & "' WHERE LastName='" & strLast & "' AND FirstName='" & strFirst & "'"

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement