Syntax error in UPDATE Statement.

Gr3g0ry

Registered User.
Local time
Today, 01:48
Joined
Oct 12, 2017
Messages
163
Dim StrSQL As String
Dim PartnerId As String
Dim Active As String
Dim EndDate As Date

Active = 0
EndDate = Date
PartnerId = Me.cboPartnerId.Value


DoCmd.RunSQL "UPDATE PARTNER SET EndDate = #" & EndDate & "#, Active = " & Active & ", WHERE PartnerID = '" & PartnerId & "'"

Me.PartnerId = Eval(Replace(Me.PartnerId.DefaultValue, "=", ""))
Me.endbtn.Enabled = False

this gives me an error: Run-time Error '3144' Syntax error in UPDATE Statement.

i cant seem to identify my error. maybe its becuz im beat ... please help
 
what is the datatype of Active?
Code:
 Active = " & Active &

also its better to use currentdb.execute

Code:
dim strSql as string
strsql = "UPDATE PARTNER SET EndDate = #" & EndDate & "#, Active = " & Active & ", WHERE PartnerID = '" & PartnerId & "'"
debug.print strSql
currentdb.execute strSql, dbfailonerror
use debug.print so you can see how it looks before executing it.
 
Last edited:
You need to find out what your UPDATE statement actually is. Youd using one language (VBA) to construct a string in another language (SQL). You need to jump out of that inception-like coding to find out what it is your SQL string.

Debug.print it
 
what is the datatype of Active?
Code:
 Active = " & Active &

also its better to use currentdb.execute

Code:
dim strSql as string
strsql = "UPDATE PARTNER SET EndDate = #" & EndDate & "#, Active = " & Active & ", WHERE PartnerID = '" & PartnerId & "'"
debug.print strSql
currentdb.execute strSql, dbfailonerror
use debug.print so you can see how it looks before executing it.

Active is an integer variable.
i just realized i had set its datatype to string. i fixed that just now and the issue is still the same. Active is being written to a lookup field YES/NO
 
Active is being written to a lookup field YES/NO

Is it a Yes/No field (values of -1 or 1) or is it a field you are looking up?

Yes/No fields normally do NOT have a lookup attached.
 
what is the datatype of Active?
Code:
 Active = " & Active &

also its better to use currentdb.execute

Code:
dim strSql as string
strsql = "UPDATE PARTNER SET EndDate = #" & EndDate & "#, Active = " & Active & ", WHERE PartnerID = '" & PartnerId & "'"
debug.print strSql
currentdb.execute strSql, dbfailonerror
use debug.print so you can see how it looks before executing it.

There is a comma before WHERE clause which is wrong. Try this:

strsql = "UPDATE PARTNER SET EndDate = #" & EndDate & "#, Active = " & Active & " WHERE PartnerID = '" & PartnerId & "'"
 

Users who are viewing this thread

Back
Top Bottom