?
Solved

selecting/updating date in access db with VB

Posted on 2003-10-28
6
Medium Priority
?
211 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 1050 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
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…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 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