Discussion Locked

USE SQL INSERT to insert dates

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can someone please tell me how to insert dates in MS Access?
when i insert dates i get an error
i use this statement
strSQ = insert into Expense (date,particulars,amount) values ('" & strDate & "','" & strParticulars & "', '" & strAmount & "')
db.execute strSQL

if i take off date, i am able to insert a record in another table, what could be the problem with inserting dates, i have tried using the #, but that does not work either..

Please help

5 replies

by bojidar alexandrov

Give, please the error message that you receive.
I now assume that your problem is that you possibly pass wrong string for your date.
As I guess amount is an numerical column but you pass a string. Also for particulars.
Dates are passed as string, but check the dokumentation how it must be formated or use some standart formating like yyyy/mm/dd.
Your sql must became
---------------
insert into Expense (date,particulars,amount)
values ('2001/10/16',2,3)
----------
Note that you don't have quote with numbers - only with strings (or dates)

by sankulpune

Hello User Deleted,

Use the following modified statements:

strSQ = insert into Expense (date,particulars,amount) values (#" & strDate & "#,'" & strParticulars & "', '" & strAmount & "')
db.CreateQueryDef ("qry1",strSQ)

1) Dates are embeded between a pair of #.
2) A select query can not be created using execute statement. You need to use CreateQueryDef method.

Hope this helps.

I would, however, be glad to provide any more specific assistance you may need in this regard.

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

This discussion is closed to new replies.