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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert a record using ADO 1

Status
Not open for further replies.

HomeGrowth

Technical User
Aug 19, 2004
76
US
I try to insert a record into a table (only 2 fields). At the cn.Execute, I have this run-time error ‘-2146217900(80040e14)’: Syntax error in INSERT INTO Statement.

I think that I am missing something in function, can you help me out?

Function CreateRefNo(sReportNumber As String, sRefNo As String) As Boolean

Dim sSql As String
Dim cn As ADODB.Connection

Set cn = CurrentProject.Connection ' This establishes the connection

sSql = "INSERT INTO tbl(2)ReferenceReportNo ( [ReportNumber], [RefReportNumber] ) VALUES ('" & sReportNumber & "','" & sRefNo & "');"

cn.Execute (sSql)

Exit_CreateRefNo:
cn.Close
Exit Function

Err_CreateRefNo:
MsgBox Err.Number & " ' " & Err.Description
Resume Exit_CreateRefNo

End Function
 
You may try this:
sSql = "INSERT INTO [!][[/!]tbl(2)ReferenceReportNo[!]][/!] ( [ReportNumber], [RefReportNumber] ) VALUES ('" & sReportNumber & "','" & sRefNo & "');"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

If your table is not going to change, you may skip ( [ReportNumber], [RefReportNumber] ) part in your INSERT SQL.

Code:
sSql = "INSERT INTO [tbl(2)ReferenceReportNo] VALUES ('" & sReportNumber & "','" & sRefNo & "');"

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top