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

Inserting Date values in Access 2000

Posted on 2002-05-31
7
172 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
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.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

791 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