INSERTING DATE

D

dthmtlgod

I am trying to insert a date into a date field through my website. The date
is pre-populated with todays date. I am getting a type mismatch error. The
Access DB is setup as a Date/Time Short Date field.

Here is the SQL string. Any ideas?

Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
PrinterName, UserName) VALUES ('MaintDate', 'SA', 'Maintenance',
'PrinterName', 'UserName')")
 
B

Bob Barrows [MVP]

dthmtlgod said:
I am trying to insert a date into a date field through my website.
The date is pre-populated with todays date. I am getting a type
mismatch error. The Access DB is setup as a Date/Time Short Date
field.

Here is the SQL string. Any ideas?

Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA,
Maintenance, PrinterName, UserName) VALUES ('MaintDate', 'SA',
'Maintenance', 'PrinterName', 'UserName')")

This statement is attempting to put the word 'MaintDate' into a field that
will only accept date/time values.

Check out these posts:
http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&[email protected]

http://www.google.com/groups?hl=en&...ows&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=10&sa=N

Bob Barrows
 
R

Ray Costanzo [MVP]

With what you have, you're trying to insert the literal text, "MaintDate."
You want to insert a date, i.e.

Conn.Execute "INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
PrinterName, UserName) VALUES (#" & Date & "#,'SA'......)"

Also, do you mean to insert the literal text of SA, Maintenance,
Printername, etc.? Or are they variables? If those are variables in your
code, they are not going to be evaluated when you execute your INSERT. All
you'll see is the actual literal text, MaintDate, SA, etc. Remember, you're
just building a string here, so if you want to concatenate variable values,
you have to do just that - concatenate the values.

sSQL = "INSERT INTO.... VALUES (#" & Date & "#,'" & SA & "','" & Maintenance
& "','" & PrinterName & "','" & Username & "')"

Response.Write sSQL

Ray at home
 
E

Egbert Nierop \(MVP for IIS\)

dthmtlgod said:
I am trying to insert a date into a date field through my website. The
date
is pre-populated with todays date. I am getting a type mismatch error.
The
Access DB is setup as a Date/Time Short Date field.

Here is the SQL string. Any ideas?

Conn.execute ("INSERT INTO PrinterMaintenance (MaintDate, SA, Maintenance,
PrinterName, UserName) VALUES ('MaintDate', 'SA', 'Maintenance',
'PrinterName', 'UserName')")

Use parameters

Set cmd.ActiveConnection = conn
cmd.CommandText = "insert into blah (dt) values(?)" ' simplified sample
cmd.CommandType = adCmdText
cmd.Parameters.Append cmd.CreateParameter(, adDBDate, 1, , Date)
cmd.Execute ,, adExecuteNoRecords
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,585
Members
45,080
Latest member
mikkipirss

Latest Threads

Top