Run Time Error '3134' - Syntax Assistance Required (1 Viewer)

lebewb

New member
Local time
Today, 18:43
Joined
Sep 4, 2018
Messages
6
Hi all,

I am building a basic form that requires several text boxes to be captured and inserted into a table appropriately, however as I have added the final textbox into my VBA code I get a 3134 error and cannot seem to find where I have gone wrong.

The code is as follows:

Private Sub cmdAdd_Click()
Dim strInsert As String
If IsNull(Me.txtPolicyNum) Or IsNull(Me.txtinception) Or IsNull(Me.txtExpiryDAte) Or IsNull(Me.txtAccountNumber) Then
MsgBox "Please complete Policy Details"
Else
strInsert = "insert into VehicleRecords (Vehicle_is_registered, State_of_Registration, Redbook_code, Full_description, Vehicle_value, Standard_accessories, yn_nonstandard_accessories, yn_vehicle_mods, Value_NSA_Mods, NS_accessories, Policy_record, Inception_Date, Expiry_Date, Account_Number, Registration_Number, State_of_base_operations, Suburb, Postcode, CoverType, Standard_excess, Imposed_excess, Total_variable_excess, No_claim_bonus_entitlement, claim_bonus_verified, protect_noclaim_bonus, Class, Make, Model, Build_Year, PremiumAmount, FireLevy, GST, StampDuty)" & _
"values( " & Me.cboVehicleRegistered & ",'" & Me.cboStateofRego & "','" & Me.txtRedbook & "','" & Me.txtFulldescription & "','" & Me.txtVehicleValue & "','" & Me.txtStandardaccessories & "','" & Me.cboNSAccessories & "','" & Me.cboMods & "','" & Me.txtModsValues & "','" & Me.txtnonstandardaccessories & "','" & Me.txtPolicyNum & "','" & Me.txtinception & "','" & Me.txtExpiryDAte & "','" & Me.txtAccountNumber & "','" & Me.txtRegoNumber & "','" & Me.cboBaseOps & "','" & Me.txtBaseOperations & "','" & Me.txtPostcode & "','" & Me.cboCoverType & "','" & Me.txtStandardaccessories & "','" & Me.txtImposedExcess & "','" & Me.txtTotalVariableExcess & "','" & Me.cboNoClaimBonusEntit & "','" & Me.cboVerifynoClaimBonus & "','" & Me.cboProtectNoClaim & "','" & Me.cboClass & "','" & Me.cboMake & "','" & Me.cboModel & "','" & Me.txtBuildYear & "','" & Me.txtPremium & "','" & Me.txtFire & "','" & Me.txtGST & "','" & Me.txtStamp & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL strInsert
DoCmd.SetWarnings True
MsgBox "Vehicle added successfully"
'add data to table

End If
'refresh data from list on form
subfrmVehicleRecords.Form.Requery
End Sub

Any assistance or suggestions would be greatly appreciated.
 

Ranman256

Well-known member
Local time
Today, 04:43
Joined
Apr 9, 2015
Messages
4,339
Have you trie using a query instead of code?
Queries tell you what is wrong.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:43
Joined
May 7, 2009
Messages
19,229
try adding space before " values("

" values (" & ...
 

isladogs

MVP / VIP
Local time
Today, 09:43
Joined
Jan 14, 2017
Messages
18,209
Have you trie using a query instead of code?
Queries tell you what is wrong.

So does SQL.
The error message should have told you which section of the code was faulty

Using code tags makes it much easier to read/check code though in your case there are so many values that it's still difficult!

In your values all except the first are for text fields. That includes one called txtAccountNumber.
Is the bound column of cboVehicleRegistered and the destination field Vehicle_Is_Registered a number field?
Do you have any other number or date fields in this sql?

Code:
Private Sub cmdAdd_Click()
Dim strInsert As String
If IsNull(Me.txtPolicyNum) Or IsNull(Me.txtinception) Or IsNull(Me.txtExpiryDAte) Or IsNull(Me.txtAccountNumber) Then
MsgBox "Please complete Policy Details"
Else
strInsert = "insert into VehicleRecords (Vehicle_is_registered, State_of_Registration, Redbook_code, Full_description, Vehicle_value, Standard_accessories, yn_nonstandard_accessories, yn_vehicle_mods, Value_NSA_Mods, NS_accessories, Policy_record, Inception_Date, Expiry_Date, Account_Number, Registration_Number, State_of_base_operations, Suburb, Postcode, CoverType, Standard_excess, Imposed_excess, Total_variable_excess, No_claim_bonus_entitlement, claim_bonus_verified, protect_noclaim_bonus, Class, Make, Model, Build_Year, PremiumAmount, FireLevy, GST, StampDuty)" & _
"values( " & Me.cboVehicleRegistered & ",'" & Me.cboStateofRego & "','" & Me.txtRedbook & "','" & Me.txtFulldescription & "','" & Me.txtVehicleValue & "','" & Me.txtStandardaccessories & "','" & Me.cboNSAccessories & "','" & Me.cboMods & "','" & Me.txtModsValues & "','" & Me.txtnonstandardaccessories & "','" & Me.txtPolicyNum & "','" & Me.txtinception & "','" & Me.txtExpiryDAte & "','" & Me.txtAccountNumber & "','" & Me.txtRegoNumber & "','" & Me.cboBaseOps & "','" & Me.txtBaseOperations & "','" & Me.txtPostcode & "','" & Me.cboCoverType & "','" & Me.txtStandardaccessories & "','" & Me.txtImposedExcess & "','" & Me.txtTotalVariableExcess & "','" & Me.cboNoClaimBonusEntit & "','" & Me.cboVerifynoClaimBonus & "','" & Me.cboProtectNoClaim & "','" & Me.cboClass & "','" & Me.cboMake & "','" & Me.cboModel & "','" & Me.txtBuildYear & "','" & Me.txtPremium & "','" & Me.txtFire & "','" & Me.txtGST & "','" & Me.txtStamp & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL strInsert
DoCmd.SetWarnings True
MsgBox "Vehicle added successfully"
'add data to table

End If
'refresh data from list on form
subfrmVehicleRecords.Form.Requery
End Sub
 
Last edited:

lebewb

New member
Local time
Today, 18:43
Joined
Sep 4, 2018
Messages
6
I have tried with the space and unfortunately it still does not work.

This code adds to a table which then is appended to a master table the user has inputted all the different vehicles. I am unsure of how to do a query prior to this step.
 

lebewb

New member
Local time
Today, 18:43
Joined
Sep 4, 2018
Messages
6
So does SQL.
The error message should have told you which section of the code was faulty

Using code tags makes it much easier to read/check code though in your case there are so many values that it's still difficult!

In your values all except the first are for text fields. That includes one called txtAccountNumber.
Is the bound column of cboVehicleRegistered and the destination field Vehicle_Is_Registered a number field?
Do you have any other number or date fields in this sql?

Code:
Private Sub cmdAdd_Click()
Dim strInsert As String
If IsNull(Me.txtPolicyNum) Or IsNull(Me.txtinception) Or IsNull(Me.txtExpiryDAte) Or IsNull(Me.txtAccountNumber) Then
MsgBox "Please complete Policy Details"
Else
strInsert = "insert into VehicleRecords (Vehicle_is_registered, State_of_Registration, Redbook_code, Full_description, Vehicle_value, Standard_accessories, yn_nonstandard_accessories, yn_vehicle_mods, Value_NSA_Mods, NS_accessories, Policy_record, Inception_Date, Expiry_Date, Account_Number, Registration_Number, State_of_base_operations, Suburb, Postcode, CoverType, Standard_excess, Imposed_excess, Total_variable_excess, No_claim_bonus_entitlement, claim_bonus_verified, protect_noclaim_bonus, Class, Make, Model, Build_Year, PremiumAmount, FireLevy, GST, StampDuty)" & _
"values( " & Me.cboVehicleRegistered & ",'" & Me.cboStateofRego & "','" & Me.txtRedbook & "','" & Me.txtFulldescription & "','" & Me.txtVehicleValue & "','" & Me.txtStandardaccessories & "','" & Me.cboNSAccessories & "','" & Me.cboMods & "','" & Me.txtModsValues & "','" & Me.txtnonstandardaccessories & "','" & Me.txtPolicyNum & "','" & Me.txtinception & "','" & Me.txtExpiryDAte & "','" & Me.txtAccountNumber & "','" & Me.txtRegoNumber & "','" & Me.cboBaseOps & "','" & Me.txtBaseOperations & "','" & Me.txtPostcode & "','" & Me.cboCoverType & "','" & Me.txtStandardaccessories & "','" & Me.txtImposedExcess & "','" & Me.txtTotalVariableExcess & "','" & Me.cboNoClaimBonusEntit & "','" & Me.cboVerifynoClaimBonus & "','" & Me.cboProtectNoClaim & "','" & Me.cboClass & "','" & Me.cboMake & "','" & Me.cboModel & "','" & Me.txtBuildYear & "','" & Me.txtPremium & "','" & Me.txtFire & "','" & Me.txtGST & "','" & Me.txtStamp & "')"
DoCmd.SetWarnings False
[COLOR="Red"]DoCmd.RunSQL strInsert[/COLOR]
DoCmd.SetWarnings True
MsgBox "Vehicle added successfully"
'add data to table

End If
'refresh data from list on form
subfrmVehicleRecords.Form.Requery
End Sub

The error is showing up as the line that says DoCmd.RunSQL

Further to your point, all fields should be text as this solution is a simple workaround at this stage and has potential variations in the format data will be entered.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 09:43
Joined
Jan 14, 2017
Messages
18,209
The error is showing up as the line that says DoCmd.RunSQL

Further to your point, all fields should be text as this solution is a simple workaround at this stage and has potential variations in the format data will be entered.

Keep the space before values which arnel spotted.
Add text delimiters to the first item in the values section
'" & cboVehicleRegistered & "'

Are you sure the bound column of the combo is text?
Are you sure the dates fields are text?

Also replace the DoCmd.RunSQL line and the two set warning lines with
Code:
CurrentDb.Execute strInsert, dbFailOnError

Finally adding error handling would simplify problem solving a lot
 
Last edited:

lebewb

New member
Local time
Today, 18:43
Joined
Sep 4, 2018
Messages
6
Keep the space before values which arnel spotted.
Add text delimiters to the first item in the values section
'" & cboVehicleRegistered & "'

Are you sure the bound column of the combo is text?
Are you sure the dates fields are text?

Also replace the DoCmd.RunSQL line and the two set warning lines with
Code:
CurrntDb.Execute strInsert, dbFailOnError

Finally adding error handling would simplify problem solving a lot

That's fantastic Colin thankyou for you help!
 

isladogs

MVP / VIP
Local time
Today, 09:43
Joined
Jan 14, 2017
Messages
18,209
You're welcome. I hope it helps

Just noticed a typo which I've corrected. It should have read
Code:
Curr[COLOR="Red"]e[/COLOR]ntDb.Execute
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:43
Joined
May 7, 2009
Messages
19,229
try searching fnAnySql in this forum.

to use it:

strInsert = "insert into VehicleRecords (Vehicle_is_registered, State_of_Registration, Redbook_code, Full_description, Vehicle_value, Standard_accessories, yn_nonstandard_accessories, yn_vehicle_mods, Value_NSA_Mods, NS_accessories, Policy_record, Inception_Date, Expiry_Date, Account_Number, Registration_Number, State_of_base_operations, Suburb, Postcode, CoverType, Standard_excess, Imposed_excess, Total_variable_excess, No_claim_bonus_entitlement, claim_bonus_verified, protect_noclaim_bonus, Class, Make, Model, Build_Year, PremiumAmount, FireLevy, GST, StampDuty) " & _
"values( p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,p26,p27,p28,p29,p30,p31,p32,p33)"

Call fnAnySql(strInsert, Me.cboVehicleRegistered, Me.cboStateofRego, Me.txtRedbook, Me.txtFulldescription, Me.txtVehicleValue, Me.txtStandardaccessories, Me.cboNSAccessories, Me.cboMods, Me.txtModsValues, Me.txtnonstandardaccessories, Me.txtPolicyNum, Me.txtinception, Me.txtExpiryDAte , Me.txtAccountNumber, Me.txtRegoNumber, Me.cboBaseOps, Me.txtBaseOperations, Me.txtPostcode, Me.cboCoverType, Me.txtStandardaccessories, Me.txtImposedExcess, Me.txtTotalVariableExcess, Me.cboNoClaimBonusEntit, Me.cboVerifynoClaimBonus, Me.cboProtectNoClaim, Me.cboClass, Me.cboMake, Me.cboModel, Me.txtBuildYear, Me.txtPremium, Me.txtFire, Me.txtGST, Me.txtStamp)
 

Users who are viewing this thread

Top Bottom