Solved

selecting/updating date in access db with VB

Posted on 2003-10-28
6
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 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