Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO syntax error

Status
Not open for further replies.

kriehn16

Technical User
Jul 1, 2008
18
0
0
US
I have a form that the user fills their information into. Then I want to take that information and put it into a new row on an existing table, however, when I try to run the code I get "syntax error in INSERT INTO statement." I am not sure what I am doing wrong. The date_of_request, first_avail_date, and mand_comp_date fields are dates, the facility, requester, industry_standard, and test_type fields are strings and the rest of the fields are numbers. If anyone has any ideas as to where the syntax error is, I would greatly appreciate the input.

stdbName = "H:\Access\SelfServeTestSchedule.mdb"

Dim stSQL As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open stdbName

stSQL = "INSERT INTO TestInfoTable (test_num, project_num, facility, requester, " & _
"date_of_request, first_avail_date, mand_comp_date, device_s/n, industry_standard, " & _
"test_type, man_dur, mach_dur) VALUES (test_num, TextBox5.Value, 'SMKE', " & _
"'ComboBox2.Value', #TextBox6.Value#, #beg_date#, #comp_date#, TextBox9.Value, " & _
"TextBox10.Value, 'test_type', 0, 0);"

cn.Execute stSQL
 
You will have to use the values, rather than references:

Code:
stSQL = "INSERT INTO TestInfoTable (test_num, project_num, facility, requester, " & _
            "date_of_request, first_avail_date, mand_comp_date, device_s/n, industry_standard, " & _
            "test_type, man_dur, mach_dur) " _
"VALUES (test_num, " & TextBox5.Value _
& ", 'SMKE', '" _
& ComboBox2.Value & "', #" & TextBox6.Value _
& "#, #" & beg_date & "#, #" & comp_date _
& "#, " & TextBox9.Value & ", " & TextBox10.Value _ & ", '" & test_type & "', 0, 0)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top