Bad INSERT INTO command???

N

Noozer

I have an ASP page that is trying to add a record to an MS Access database,
but I'm getting a MS Jet error 80040e14. Syntax error in INSERT INTO
statement.

The INSERT command I'm using is:

INSERT INTO Calls (Who, When) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

...where "Who" is a 16 character text field and When is a General format
Date/Time field. The only other field in the Calls table is "CallID" with is
an autonumber.

Code I'm using is:

'Create database objects
set adoCon = server.CreateObject("ADODB.Connection")
set rsSet = server.CreateObject("ADODB.Recordset")

'Connect to database
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("Calls.mdb")

'Add Call to database
strSQL="INSERT INTO Calls (Who, When) VALUES ('" & AgentIP & "', #" & When
& "#);"
rsSet.open strSQL, adoCon

....any idea's why this is happening? I believe it has something to do with
the date, but I can't figure it out.

Thx!
 
N

Noozer

INSERT INTO Calls (Who, When) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

OK, I'm an idiot... WHEN is a reserved word.

INSERT INTO Calls (Who, [When]) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

....works.
 
N

Noozer

Noozer said:
INSERT INTO Calls (Who, When) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

OK, I'm an idiot... WHEN is a reserved word.

INSERT INTO Calls (Who, [When]) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

Table has has it's columns renamed, the SQL statement below matches what the
Calls table columns are named. Now it can't find the columns!


INSERT INTO Calls (IP, Submitted) VALUES ("10.0.94.11", #1/18/2005 10:34:42
AM#);
ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name
or ordinal.
 
G

Guest

I don't think you can perform an action query with an open command.

Try changing your rsSet.Open to

adoCon.Execute strsql

HTH
Dale


Noozer said:
INSERT INTO Calls (Who, When) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

OK, I'm an idiot... WHEN is a reserved word.

INSERT INTO Calls (Who, [When]) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

....works.
 
N

Noozer

OK, I'm an idiot... WHEN is a reserved word.
INSERT INTO Calls (Who, [When]) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

Table has has it's columns renamed, the SQL statement below matches what the
Calls table columns are named. Now it can't find the columns!


INSERT INTO Calls (IP, Submitted) VALUES ("10.0.94.11", #1/18/2005 10:34:42
AM#);
ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name
or ordinal.

....and I'm still an idiot. Made a typo when I renamed the columns.
 
N

Noozer

Thanks... I was hoping to use the recordset to get the Autonumber generated
after the insert.

The table I'm inserting into has three columns, "Call ID" which is an
autonumber, plus the two columns below.

How can I read the CallID autonumber after doing the insert?

Thx!


Dale Fye said:
I don't think you can perform an action query with an open command.

Try changing your rsSet.Open to

adoCon.Execute strsql
INSERT INTO Calls (Who, When) VALUES ('10.0.94.11', #1/18/2005
9:56:37
AM#)

OK, I'm an idiot... WHEN is a reserved word.

INSERT INTO Calls (Who, [When]) VALUES ('10.0.94.11', #1/18/2005 9:56:37
AM#)

....works.
 
G

Guest

The autonumber function of Access generates a new number each time an item is
inserted into a table. This number is always increasing, so your best bet
would be to write a SQL string to select the MAX() value from your autonumber
field, right after you execute the other SQL. The down side of this would be
that if someone else performs the same function, at almost exactly the same
time, they could insert to the table between your insert and your select.

Another way would be to write a select statement that looks at your [Who]
and [When] fields in a where clause, something like:

SELECT MAX([ID]) as ID_Value
FROM yourTable
WHERE [Who] = '10.0.94.11'
AND [WHEN] = #1/18/2005 9:56:37#

This would be much less likely to have the previously described situation
occur.

HTH
Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top