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
Solved

selecting/updating date in access db with VB

Posted on 2003-10-28
6
205 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

840 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