Syntax error in my form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

By clicking on command button, I am updating field 'Type'
in my table. But i have wrong syntax in my code.

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = strPath"

Please show me what syntax should i put around "strPath".

Thank you for help.
 
Try this:

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = " & strPath

or

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = '"& strPath &"'
 
You left off one quote on the second version and the & has to have spaces on
either side of it or it will fail.

I would also recommend the Execute method of the CurrentDb object instead on
RunSQL. That is because it is much faster and it not affected by
SetWarnings. It does not go through the Access UI.

CurrentDb.Execute("UPDATE Test SET Test.[Type] = '" & strPath & "'"),
dbFailOnError


Should be:
DoCmd.RunSQL "UPDATE Test SET Test.[Type] = '" & strPath & "'"

D' Polygon said:
Try this:

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = " & strPath

or

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = '"& strPath &"'

By clicking on command button, I am updating field 'Type'
in my table. But i have wrong syntax in my code.

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = strPath"

Please show me what syntax should i put around "strPath".

Thank you for help.
 
Thank you so much.
I used Execute method of the CurrentDb object you recomended, It works
perfect.


Klatuu said:
You left off one quote on the second version and the & has to have spaces on
either side of it or it will fail.

I would also recommend the Execute method of the CurrentDb object instead on
RunSQL. That is because it is much faster and it not affected by
SetWarnings. It does not go through the Access UI.

CurrentDb.Execute("UPDATE Test SET Test.[Type] = '" & strPath & "'"),
dbFailOnError


Should be:
DoCmd.RunSQL "UPDATE Test SET Test.[Type] = '" & strPath & "'"

D' Polygon said:
Try this:

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = " & strPath

or

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = '"& strPath &"'

By clicking on command button, I am updating field 'Type'
in my table. But i have wrong syntax in my code.

DoCmd.RunSQL "UPDATE Test SET Test.[Type] = strPath"

Please show me what syntax should i put around "strPath".

Thank you for help.
 
Back
Top