MSACCESS SQL Error 3021 - Updates Locally but not to Server - sql

I have an already existing form that I added one new textbox to that allows the user to input notes. I have 2 queries that run when the submission button is clicked, one to update a local table within MSACCESS and the other is on our server. The new button is called DISPATCH_NOTES, it is also the name of the column in the tables.
BEFORE (Working)
LOCAL:
strSQL = "UPDATE WCL_DATABASE_QUERY " & vbNewLine & _
"SET WCL_DATABASE_QUERY.COMMENTS ='" & Me.COMMENTS.Value & "',WCL_DATABASE_QUERY.DISPATCH_NOTES ='" & Me.DISPATCH_NOTES.Value & "', WCL_DATABASE_QUERY.TRAFFIC_SPECIALIST ='" & GetUsername & "', WCL_DATABASE_QUERY.PLANNED_SHIP_DATE = " & PSD & "WCL_DATABASE_QUERY.LAST_UPDATE =#" & Now() & "#" & vbNewLine & _
"WHERE (((WCL_DATABASE_QUERY.CUSTOMER_PURCHASE_ORDER_ID) in ('" & Join(POList, "', '") & "'))) AND ORDER_STATUS = 'OPEN';"
CurrentDb.Execute strSQL, dbFailOnError
Before (Working) SERVER:
strSQL = "UPDATE TrafficDatabase_Query " & vbNewLine & _
"SET TrafficDatabase_Query.COMMENTS ='" & Me.COMMENTS.Value & "', TrafficDatabase_Query.DISPATCH_NOTES ='" & Me.DISPATCH_NOTES.Value & "', TrafficDatabase_Query.TRAFFIC_SPECIALIST ='" & GetUsername & "', TrafficDatabase_Query.PLANNED_SHIP_DATE = " & PSD & "TrafficDatabase_Query.LAST_UPDATE =#" & Now() & "#" & vbNewLine & _
"WHERE (((LTRIM(RTRIM(TrafficDatabase_Query.CUSTOMER_PURCHASE_ORDER_ID)) & TrafficDatabase_Query.DELIVERY_NUMBER) in (" & PODO & ")));"
CurrentDb.Execute strSQL, dbFailOnError
After (Working) LOCAL:
strSQL = "UPDATE WCL_DATABASE_QUERY " & vbNewLine & _
"SET WCL_DATABASE_QUERY.COMMENTS ='" & Me.COMMENTS.Value & "',WCL_DATABASE_QUERY.DISPATCH_NOTES ='" & Me.DISPATCH_NOTES.Value & "', WCL_DATABASE_QUERY.TRAFFIC_SPECIALIST ='" & GetUsername & "', WCL_DATABASE_QUERY.PLANNED_SHIP_DATE = " & PSD & "WCL_DATABASE_QUERY.LAST_UPDATE =#" & Now() & "#" & vbNewLine & _
"WHERE (((WCL_DATABASE_QUERY.CUSTOMER_PURCHASE_ORDER_ID) in ('" & Join(POList, "', '") & "'))) AND ORDER_STATUS = 'OPEN';"
CurrentDb.Execute strSQL, dbFailOnError
After (Broken) SERVER:
strSQL = "UPDATE TrafficDatabase_Query " & vbNewLine & _
"SET TrafficDatabase_Query.COMMENTS ='" & Me.COMMENTS.Value & "', TrafficDatabase_Query.DISPATCH_NOTES ='" & Me.DISPATCH_NOTES.Value & "', TrafficDatabase_Query.TRAFFIC_SPECIALIST ='" & GetUsername & "', TrafficDatabase_Query.PLANNED_SHIP_DATE = " & PSD & "TrafficDatabase_Query.LAST_UPDATE =#" & Now() & "#" & vbNewLine & _
"WHERE (((LTRIM(RTRIM(TrafficDatabase_Query.CUSTOMER_PURCHASE_ORDER_ID)) & TrafficDatabase_Query.DELIVERY_NUMBER) in (" & PODO & ")));"
CurrentDb.Execute strSQL, dbFailOnError
This is the Debug.Print strSQL before the LOCAL:
UPDATE WCL_DATABASE_QUERY
SET WCL_DATABASE_QUERY.COMMENTS ='Sent to Dispatch',WCL_DATABASE_QUERY.DISPATCH_NOTES ='Please ship these PO's 1st, they have been coded WCLA.', WCL_DATABASE_QUERY.TRAFFIC_SPECIALIST ='JRussi', WCL_DATABASE_QUERY.PLANNED_SHIP_DATE = Null, WCL_DATABASE_QUERY.LAST_UPDATE =#10/19/2021 1:41:57 PM#
WHERE (((WCL_DATABASE_QUERY.CUSTOMER_PURCHASE_ORDER_ID) in ('6596145'))) AND ORDER_STATUS = 'OPEN';

Related

Access VBA using SQL UPDATE

I'm using two Access databases (front end and back end).
My code for query work, but I get it to work with updating the database. What am I doing wrong?
I get a runtime error 3078 for the DoCmd.RunSQL strSql on line 25.
Set cnn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & CurrentProject.Path & "\DB_Cryk.accdb"
cnn.Open strConnection
MemberID = txtMemberID.Value
strSql = "UPDATE Cryk " & _
"SET Membership = '" & txtMembership.Value & "', " & _
" Memberstatus = '" & txtMemberstatus.Value & "', " & _
" Membername = '" & txtMembername.Value & "', " & _
" Memberaddress = '" & txtMemberaddress.Value & "', " & _
" Memberzip = '" & txtMemberzip.Value & "', " & _
" Membercity = '" & txtMembercity.Value & "', " & _
" Memberphone = '" & txtMemberphone.Value & "', " & _
" Membermail = '" & txtMembermail.Value & "', " & _
" Memberyear = '" & txtMemberyear.Value & "', " & _
" Dateofbirth = '" & txtDateofbirth.Value & "', " & _
" Memberno = '" & txtMemberno.Value & "', " & _
" Memberfee = '" & txtMemberfee.Value & "', " & _
" Memberpayment = '" & txtMemberpayment.Value & "'" & _
"WHERE MemberID= '" & MemberID & "'"
DoCmd.RunSQL strSql
cnn.Close
Set cnn = Nothing
Error 3078 indicates that the target table does not exist in your database.
Note that, although you open an ADO connection to the database DB_Cryk.accdb, you execute your SQL statement using the DoCmd.RunSQL method, which operates on the current database.
Instead, if you want the SQL to be executed in your DB_Cryk.accdb database, you should use the Execute method of the ADODB Connection object, e.g.:
cnn.Execute strsql
Where query parameterization is concerned, you may wish to refer to this superb answer, specifically, the 'Using ADO' section.

SQL UPDATE syntax error issue

I have some SQL where I am getting a syntax error, but cant work out why:
The Code:
CurrentDb.Execute "UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBnameVoice & "].[" & tblhistoric & "] " & _
"SET NudgeSent = '" & SendNudge & "' " & _
"WHERE [ID] = '" & UID & "'"
Why I am confused:
I have the exact same code but to update a different column and it works fine, what am I missing?
Error Received:
Syntax error in UPDATE Statement
Similar code I have the does work:
CurrentDb.Execute "UPDATE [MS Access;pwd=" & strPassword & ";database=" & DBpath & "\" & DBnameVoice & "].[" & tblhistoric & "] " & _
"SET AllocatedTo = '" & Allocateto & "' " & _
"WHERE [ID] = '" & UID & "'"

MA run-time error '3075' Syntax Error

i have this code and it shows me run-time error '3075' Syntax Error and i dont know how to fix it . help me please
CurrentDb.Execute "UPDATE PUNONJESIT set Id_punonjesit= '" & Me.id & "', Emer_punonjesi ='" & Me.emri & "', Mbiemer_punonjesi='" & Me.mbiemri & ", Mosha='" & Me.mosha & "', Profesioni='" & Me.profesioni & "', Rroga='" & Me.rroga & "', WHERE Id_punonjesit ='" & Me.id & "'"
I'm not sure the manual data (e.g. Me.id) is retrieve from text box properties or otherwise? If they are text boxes, then you should change them to this (e.g. Me.id.value) so the access can retrieve the value.
Here is my suggestion below:
(You)
CurrentDb.Execute "UPDATE PUNONJESIT set Id_punonjesit= '" & Me.id & "', Emer_punonjesi ='" & Me.emri & "', Mbiemer_punonjesi='" & Me.mbiemri & ", Mosha='" & Me.mosha & "', Profesioni='" & Me.profesioni & "', Rroga='" & Me.rroga & "', WHERE Id_punonjesit ='" & Me.id & "'"
(Me)
CurrentDb.Execute "UPDATE PUNONJESIT set Id_punonjesit=" & Me.id.value & ", Emer_punonjesi =" & Me.emri.value & ", Mbiemer_punonjesi=" & Me.mbiemri.value & ", Mosha=" & Me.mosha.value & ", Profesioni=" & Me.profesioni.value & ", Rroga=" & Me.rroga.value & ", WHERE Id_punonjesit =" & Me.id.value & ";"
You can try it and see what error does it generate. Do let me know if it helps? (:

Syntax error in UPDATE statement vb and ms.access as database

I am trying to make medical record application for my assignment. I found this error to edit data patient.
Please help and sorry for my bad grammar
Dim aksesedit As String = "Update tbpasien set " & _
"Nama_Pasien='" & txtnamapasien.Text & "', " & _
"Jenis_Kelamin='" & cmbjk.Text & "'," & _
"Tempat_Pasien='" & txttempatlahir.Text & "', " & _
"Tanggal_Lahir='" & tanggallahir.Text & "', " & _
"Alamat='" & txtalamat.Text & "', " & _
"Kelurahan_Desa='" & txtkeldesa.Text & "', " & _
"Kecamatan='" & txtkec.Text & "', " & _
"Kota_Kabupaten='" & txtkotakab.Text & "', " & _
"No_Telepon_HP='" & txtnotelp.Text & "', " & _
"Agama='" & cmbagama.Text & "', " & _
"Kewarganegaraan='" & cmbwarga.Text & "', " & _
"Status_Pernikahan='" & cmbstatus.Text & "', " & _
"Pekerjaan='" & txtpekerjaan.Text & "', " & _
"where No_RM='" & txtnorm.Text & "'"
cmd = New OleDbCommand(aksesedit)
cmd.Connection = conn
cmd.ExecuteNonQuery()
syntax error in update was on here
cmd.ExecuteNonQuery()
For "Tanggal_Lahir" i used datetimepicker, cmb=combobox, txt=textbox
Thanks
There should be no comma before the WHERE clause:
"Pekerjaan='" & txtpekerjaan.Text & "' " & _
"where No_RM='" & txtnorm.Text & "'"

Vb6 Sql update query

what is wrong in this code i get syntax error from this query
ssql = "UPDATE karakter SET lvl='" & Form1.Label7.Caption & "','" & hp = Form1.Label18.Caption & "','" & mp = Form1.Label17.Caption & "','" & para = Form1.Label19.Caption & "','" & yuzde = Form1.Label16.Caption & "' WHERE id='" & Form1.Label5.Caption & "'"
You have wrong positions for you quotes.
ssql = "UPDATE karakter SET lvl='" & Form1.Label7.Caption & "', " & _
"hp ='" & Form1.Label18.Caption & "', " & _
"mp ='" & Form1.Label17.Caption & "', " & _
"para ='" & Form1.Label19.Caption & "', " & _
"yuzde ='" & Form1.Label16.Caption & "' " & _
"WHERE id='" & Form1.Label5.Caption & "'"
I suggest to use the parameters instead of concatenation.