PDA

View Full Version : Syntax Error In SQL Update Query Statement



ashu1990
06-07-2013, 12:09 PM
Hi All,

i am trying to run a update code from vba through adodb connection my Db is .MDB,
while runnign the update query i am getting "syntax error in update statement" error please help
As i am :confused: where i did it worng
my code so far


Private Sub save_btn_Click()
endtime = Format(Now(), "HH:MM:SS")
dat = Format(Now(), "DD/MM/YYYY")
num = Me.unique_text.Text
str1 = "update [Tab] set Territory ='" & Me.com_ter.Value & "',Tower = '" & Me.com_tow.Value & "',Activity ='" & Me.com_activity.Value & "',Sub_Activity ='" & Me.com_subactivity.Value & "',Processor_Name = '" & Me.com_processor.Value & "',Start_Time ='" & starttime & "',Received_Date=#" & Me.received_text.Text & "#,Due_Date =#" & Me.due_text.Text & "#,Processed_Date=#" & Me.processed_text.Text & "#,Subject='" & Me.subject_text.Text & "',Comments='" & Me.comments_text.Text & "',Action='" & Me.com_status.Value & "',Reason ='" & Me.reason_text.Text & "',End_Time='" & endtime & "',Status_Date=#" & dat & "# where tab.Id = " & num
Me.open_connection_product

con.Execute str1

Module1.close_connection

End Sub

Public Sub open_connection_product()
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset

path = Sheets("PRG").Range("A65536").Value
constring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";Jet OLEDB:Database Password=pass"

If con.State = 0 Then
con.Open constring
End If
End Sub

ashu1990
06-07-2013, 02:36 PM
for those searching the same answer;
i got it working the reason error occured was due to no space given after each "=" ;)

cheers :cheerclink:

Transformer
06-08-2013, 09:48 AM
for those searching the same answer;
i got it working the reason error occured was due to no space given after each "=" ;)

cheers :cheerclink:

Hi Ashu,
It was not beacause of no spaces after '='. You were getting an error because there is a field named 'Action' in your table,that is a keyword.Put that in square brackets. e.g. [Action]

ashu1990
06-11-2013, 11:48 AM
Hey thanks transformer.. :rolleyes:
i did the both adding space and the brackets together so forgot :wakeup: to mentioned that thanks for the reply..