Solved

selecting/updating date in access db with VB

Posted on 2003-10-28
6
203 Views
Last Modified: 2010-05-01
Hello,
I'm using VB6 and access 97. I have a column that holds the date, the date inserted to the table is taken from the system with this function:
today = Format(Now,"dd/mm/yy"),
the SQL is:
strsql = "INSERT INTO myTable(name,eDate) VALUES ('richard', "   & today & " ' )"
the problem is that when i insert the date as a string with ' ' the date apears good in the table but if i try to execute a select/update by the date then it gives nothing -
SELECT * FROM myTable where eDate = '28/10/03' returns adata type mismatch,
 and when i do
SELECT * FROM myTable where eDate = 28/10/03 then 0 records is returned
note thet when I insert the date without '  ' it inserts random date and time
Hope u can asist me ASAP
thanks

0
Comment
Question by:zolpo
6 Comments
 
LVL 8

Expert Comment

by:ampapa
ID: 9633602
Try surrounding the date with #28/10/03#
0
 
LVL 1

Author Comment

by:zolpo
ID: 9633659
thanks but ---
I tried already, it didnt work
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 350 total points
ID: 9633663
Hi zolpo,

To add to that, ALWAYS use american or other non-ambiguous date:

"Select * FROM MyTable Where eDate = #" & Format(today,"yyyy-mm-dd") & "#"

Access will always interpret dates based on mm/dd/yy first regardless of the regional settings of the machine. The use of yyyy-mm-dd gets over this problem as this will always be interpreted correctly and will not confuse dates such as 04/05 between 4th may or 5th april.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:zolpo
ID: 9633779
Thanks TimCottee ,
I tried to insert as an american date, but still the select returns 0 records
(the sql is: SELECT * from myTable where eDate = #03/10/28#)
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 9633850
SELECT * from myTable where eDate = #2003/10/28# '<-- as per TimCottee's comment 4 digit year.
0
 
LVL 1

Author Comment

by:zolpo
ID: 9634206
Thanks TimCotte,
The problem is solved,
The strange thing is- that when I insert the date to the table then I have to insert it as an american date, and when I'm executing a query that uses the date I write it as an English date, and thats the only way it works!
I guess it is because the design pattern I did on the date column.
thanks You All!!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now