VBA SQL Code to Update Field

Trevor G

Registered User.
Local time
Today, 16:33
Joined
Oct 1, 2009
Messages
2,367
I have the following code to try and update a field but it seems to fail at the strSQL statement with Error Number 3129 coming up, doesn't recognise UPDATE.

One field called SlipId has records which begin with "L" and where they can be found I a requirement to update a field called Headings with Binder Decs Earn

Function upDatePhoenix3()
Dim strSQL As String
strSQL = "UPDATE [Combined data:Phoenix] Set [Combined data:Phoenix].Headings = 'Binder Decs Earn' "
strSQL = "WHERE ((([Combined data:Phoenix].SlipId) Like 'L*')); "
Debug.Print strSQL
DoCmd.RunSQL strSQL
End Function
 
You haven't added your first string to your second string in that code, so have only a query starting at your WHERE statement.

Code:
strSQL = strSQL & "WHERE ((([Combined data:Phoenix].SlipId) Like 'L*'));"

This will solve that problem.
 
I have fixed this, I missed the strSQL before the Where statement.

It now functions in the way I want it to. Code is as follows:

Function upDatePhoenix3()
Dim strSQL As String
strSQL = "UPDATE [Combined data:Phoenix] Set [Combined data:Phoenix].Headings = 'Binder Decs Earn' "
strSQL = strSQL & "WHERE ((([Combined data:Phoenix].SlipId) Like 'L*')); "
Debug.Print strSQL
DoCmd.RunSQL strSQL
End Function
 
You haven't added your first string to your second string in that code, so have only a query starting at your WHERE statement.

Code:
strSQL = strSQL & "WHERE ((([Combined data:Phoenix].SlipId) Like 'L*'));"

This will solve that problem.


Thank you, I just got to resolve this and posted back when I got your very kind solution.
 

Users who are viewing this thread

Back
Top Bottom