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

Help with Insert Statement 1

Status
Not open for further replies.

ptuck

MIS
Aug 8, 2003
130
US
Do you all see anything wrong with this code:

'Create ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set active connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("Database\DB.mdb")
strSQL = "INSERT INTO tblData (FName, LName, Month) VALUES ('John', 'Doe', 'May')"
adoCon.Execute (strSQL)

I want to insert data from a form, but continue to get Syntax error in insert statment. So I have taken the insert statement to constant values trying to find the error. When I write the statement to the screen all the data appears, but when I excute the statement I get the syntax error. Any thoughts???

Thanks,
Paul
 
Month is a reserve word. Try this:

strSQL = "INSERT INTO tblData (FName, LName, [Month]) VALUES ('John', 'Doe', 'May')"


-VJ
 
Thanks for the quick response and you were right on target. You guys are great!!!!!!!!!!!!!!!!!!!!
 
One more question. How can I split an SQL statement up over multiple lines. I am never successful at doing this.
 
You can follow any of the below two methods:

strSQL = "INSERT INTO tblData (FName, LName, [Month]) "
strSQL = strSQL & " VALUES ('John', 'Doe', 'May') "

or

strSQL = "INSERT INTO tblData (FName, LName, [Month])" &_
strSQL = " VALUES ('John', 'Doe', 'May')"


-VJ

 
I am now getting an error on type mismatch. How do send a number value to Access? In other words, what do I enclose my variable with ('"&number&"' or number)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top