Insert Into Statement problem

BrandonM30

New member
Local time
Today, 15:28
Joined
Sep 16, 2016
Messages
9
Good afternoon all,

I am having a problem with my insert into statements. I have different types of form controls, combo boxes, text fields, and date fields pulling different kinds of data, names, numbers, dates, etc. and putting them my table, I keep getting syntax errors, and I have no idea why.

Please help, and thank you.

Public Sub cmdAppendToRecLog_Click()
MsgBox "Appending Transaction to Receiving Log"
Dim strquery As String
strquery = "INSERT INTO [RLTest] " & _
"([Date1], [Text1], [Text2], [Number1], [Number2], [Number3], [Text3], [Number4], [Number5], [Text4], [Number6], [Text5], [Number7], [Number8], [Text6], [Date2], [Text7], [Number9], [Text8], [Text9])" & _
"VALUES(" & _
"#" & Me.txtDate1.Value & "#" & _
"" & Me.cmbText1.Value & "," & _
"" & Me.cmbText2.Value & "," & _
"" & Me.txtNumber1.Value & "," & _
"" & Me.cmbNumber2.Value & "," & _
"" & Me.cmbNumber3.Value & "," & _
"" & Me.txtText3.Value & "," & _
"" & Me.cmbNumber4.Value & "," & _
"" & Me.cmbNumber5.Value & "," & _
"" & Me.cmbText4.Value & "," & _
"" & Me.cmbNumber6.Value & "," & _
"" & Me.cmbText5.Value & "," & _
"" & Me.txtNumber7.Value & "," & _
"" & Me.txtNumber8.Value & "," & _
"" & Me.cmbText6.Value & "," & _
"#" & Me.txtDate2.Value & "#" & _
"" & Me.cmbText7Value & "#" & _
"" & Me.txtNumber9.Value & "," & _
"" & Me.cmbText8.Value & "," & _
"" & Me.txtText9.Value & "," & _
")"
DoCmd.RunSQL strquery
MsgBox "Transaction has been appended to the Receiving Log"
 
Don't try to eat your elephant all at once. Take a bite, then add more bites.

Get it to work for just Date1. When you have that working get it to work for Date1 and Text1. When you have that working get it to work for Date1, Text1 and Text2. When you have that working...
 
I have done it line by line, and it always stops at the second form control
 
Your text values need quote marks

"'" & Me.cmbText1.Value & "'," & _

and as pbaldy said your first and last commas are wrong.
 

Users who are viewing this thread

Back
Top Bottom