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? (:
Related
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';
I'm doing a project and I just used some code from YouTube where it seemed to work, but it isn't working for me. I am getting this message. :/
Run-time Error: '3134':
Syntax Error in INSERT INTO statement.
Here's the code:
Private Sub Dodaj_Click()
CurrentDb.Execute "INSERT INTO Rezervacije( JMBG, Grad, Broj dana, Broj osoba) " & _
" VALUES('" & Me.JMBG & "', '" & Me.Destinacija & "', '" & Me.Dani & "', '" & Me.Osobe & "')"
CurrentDb.Execute "INSERT INTO Putnici(Broj licne karte, Ime, Prezime, JMBG, Mobilni, Email, Pol) " & _
" VALUES('" & Me.Licna & "', '" & Me.Ime & "', '" & Me.Prezime & "', '" & Me.JMBG & "', '" & Me.Mobilni & "', '" & Me.Email & "', '" & Me.Pol & "')"
End Sub
I'm trying to build a database and ran into a problem with the syntax in an UPDATE statement. Does anyone know what's wrong with the statement?
I've tried adjusting the use of single and double quotes but it's still not working.
CurrentDb.Execute "INSERT INTO tbl_SponsorContacts (ContactName, ContactEmail, ContactPhone, SponsorID )" _
& " VALUES ('" & Me.txtContactName & "','" & Me.txtContactEmail & "', '" & Me.txtContactPhone & "' , '" & Me.txtSpnID & "')"
Else
CurrentDb.Execute "UPDATE tbl_SponsorContacts SET ContactName = " _
& " '" & Me.txtContactName & "', ContactEmail = '" & Me.txtContactEmail & "', " _
& " ContactPhone = '" & Me.txtContactPhone & "', SponsorID = '" & Me.txtSpnID & "', WHERE ContactID = '" & Me.txtContactID & "'"
End If
Exit Sub
I keep getting the 3144 syntax error which doesn't provide any hints as to the cause. Any help is appreciated.
UPDATE: Thanks to Jerry M. and forpas for suggesting to remove the comma before where. That helped but I am not getting an error 3061, "Too few parameters. Expected 1".
I will post a new question.
As #forpas mentioned in the comments, it looks like you have an extra ,
Try below:
CurrentDb.Execute "INSERT INTO tbl_SponsorContacts (ContactName, ContactEmail, ContactPhone, SponsorID )" _
& " VALUES ('" & Me.txtContactName & "','" & Me.txtContactEmail & "', '" & Me.txtContactPhone & "' , '" & Me.txtSpnID & "')"
Else
CurrentDb.Execute "UPDATE tbl_SponsorContacts SET ContactName = " _
& " '" & Me.txtContactName & "', ContactEmail = '" & Me.txtContactEmail & "', " _
& " ContactPhone = '" & Me.txtContactPhone & "', SponsorID = '" & Me.txtSpnID & "'WHERE ContactID = '" & Me.txtContactID & "'"
End If
Exit Sub ```
I have written the following Insert Into statement in Access 2010 VBA:
Private Sub AddBPSSButton_Click()
' CurrentDb.Execute "INSERT INTO TabClearDetail(C_Site) VALUES(" & Me.C_Site & ")"
Dim strSQL As String
'MsgBox Me.[Clearance Applying For]
'MsgBox Me.[Contract Applying for]
'MsgBox Me.[C_Site]
'MsgBox Me.[C_SponsorSurname]
'MsgBox Me.[C_SponsorForename]
'MsgBox Me.[C_SponsorContactDetails]
'MsgBox Me.[C_EmploymentDetail]
'MsgBox Me.[C_SGNumber]
'MsgBox Me.[C_REF1DateRecd]
'MsgBox Me.[C_REF2DateRecd]
'MsgBox Me.[C_IDDateRecd]
'MsgBox Me.[C_IDNum]
'MsgBox Me.[C_CriminalDeclarationDate]
'MsgBox Me.[Credit Check Consent]
'MsgBox Me.[C_CreditCheckDate]
'MsgBox Me.[Referred for Management Decision]
'MsgBox Me.[Management Decision Date]
'MsgBox Me.[C_Comment]
'MsgBox Me.[C_DateCleared]
'MsgBox Me.[C_ClearanceLevel]
'MsgBox Me.[C_ContractAssigned]
'MsgBox Me.[C_ExpiryDate]
'MsgBox Me.[C_LinKRef]
'MsgBox Me.[C_OfficialSecretsDate]
strSQL = "INSERT INTO TabClearDetail(Clearance Applying For, Contract Applying for, " & _
"C_Site, C_SponsorSurname, C_SponsorForename, C_SponsorContactDetails, C_EmploymentDetail, " & _
"C_SGNumber, C_REF1DateRecd, C_RED2DateRecd, C_IDDateRecd, C_IDNum, " & _
"C_CriminalDeclarationDate, Credit Check Consent, C_CreditCheckDate, Referred for Management Decision, " & _
"Management Decision Date, C_Comment, C_DateCleared, C_ClearanceLevel, C_ContractAssigned, " & _
"C_ExpiryDate, C_LinkRef, C_OfficialSecretsDate) VALUES('" & Me.[Clearance Applying For] & "', " & _
"'" & Me.[Contract Applying for] & "', '" & Me.[C_Site] & "', '" & Me.[C_SponsorSurname] & "', " & _
"'" & Me.[C_SponsorForename] & "', '" & Me.[C_SponsorContactDetails] & "', " & _
"'" & Me.[C_EmploymentDetail] & "', '" & Me.[C_SGNumber] & "', '" & Me.[C_REF1DateRecd] & "', " & _
"'" & Me.[C_REF2DateRecd] & "', '" & Me.[C_IDDateRecd] & "', '" & Me.[C_IDNum] & "', " & _
"'" & Me.[C_CriminalDeclarationDate] & "', '" & Me.[Credit Check Consent] & "', '" & Me.[C_CreditCheckDate] & "', " & _
"'" & Me.[Referred for Management Decision] & "', '" & Me.[Management Decision Date] & "', " & _
"'" & Me.[C_Comment] & "', '" & Me.[C_DateCleared] & "', '" & Me.[C_ClearanceLevel] & "', " & _
"'" & Me.[C_ContractAssigned] & "', '" & Me.[C_ExpiryDate] & "', '" & Me.[C_LinKRef] & "', " & _
"'" & Me.[C_OfficialSecretsDate] & "');"
DoCmd.RunSQL (strSQL)
'MsgBox strSQL
End Sub
All The MsgBox calls work, so I believe I have typed all column names and text box names correctly. I am getting a Syntax error when I get to the DoCmd.RunSQL line. Have been staring at this for quite a while trying to see if I have missed a comma or speech mark or something, but am hoping maybe another set of eyes will see my mistake.
Any help will be greatly appreciated.
Thanks!
When you have spaces in your object names you need to enclose the full name in brackets. So where you have:
INSERT INTO TabClearDetail(Clearance Applying For, Contract Applying for,...
It should be
INSERT INTO TabClearDetail([Clearance Applying For], [Contract Applying for],...
For what it's worth I personally can't stand special characters in object names for exactly this reason, if it's not too late you should consider renaming your columns. Pascal Case is usually clear enough for compound names, e.g. ClearanceApplyingFor. Or use under scores - Clearance_Applying_For.
I also think the convention in Access is to qualify dates with # rather than single quotes, i.e. #01/01/2014#, instead of `01/01/2014'
Either you try enclosing the date fields with "#" instead of "'" or change your database's "SQL Server Compatible Syntax" property.
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.