Solved

Inserting Date values in Access 2000

Posted on 2002-05-31
7
171 Views
Last Modified: 2010-05-02
I have an Access 2000 database with a table that has a number of Date/Time fields in it. Each field is set to format Short Date.

When in Visual Basic 6 I try and Insert a row into the table, I use the Execute method of an ADO connection object to run an in-line SQL statement. The Dates which are to be entered are all in correct Short Date format. The row is entered but all the Date/Time fields all show their value as 30/12/1899.

Why is this?
How come the correct date from the SQL statement aren't saved?
0
Comment
Question by:HelpAndy
  • 4
  • 2
7 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7047473
The way the data is formatted in Access is totally unrelated to how it is stored.  Try saving with mdy format, also post your code and we can be in a better position to help you.

Anthony
0
 

Author Comment

by:HelpAndy
ID: 7047479
Up till now I have used:
myConn.Execute "INSERT INTO Holidays (DateFrom, DateTo) VALUES (" & dtDateFrom & "," & dtDateTo & ");"

dtDateForm and dtDateTo are local varaibles of the Date type.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7047488
I have not worked much with Acc2000 but How about this...

myConn.Execute "INSERT INTO Holidays (DateFrom, DateTo) VALUES (#" & dtDateFrom & "#,#" & dtDateTo & "#);"
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:HelpAndy
ID: 7047523
It works and the correct dates are put in but one of the dates is getting the day and month the wrong way around.
It seems to only happen if the date of day is less than 12.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 7047534
Use the following format for your dates: yyyy-mm-dd

So to build on gencross's solution:
Const YMDMask = "yyyy-mm-yy"
myConn.Execute "INSERT INTO Holidays (DateFrom, DateTo) VALUES (#" & Format$(dtDateFrom, YMDMask) & "#,#" & Format$(dtDateTo, YMDMask) & 
"#);"
0
 

Author Comment

by:HelpAndy
ID: 7047542
I like it perkins hold on a sec...
0
 

Author Comment

by:HelpAndy
ID: 7047561
Thank you very much and others for your input.
It was creating and formating to the Constant that ensured the date went in correctly.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 76
SSRS expression Issue finding a string 10 79
Protecting vb6 & .Net code Obfuscation 18 125
Export Data to Different .csv Files 26 105
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 …
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.
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…
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…

803 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