Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Insert Issue 1

Status
Not open for further replies.

MasterRacker

New member
Oct 13, 1999
3,343
US
I have the following test code in an application:
Code:
Dim BatchDate As Date
...
    BatchDate = Date
    db.Execute "INSERT INTO BatchData (BatchDate,RecipeID) VALUES (" & BatchDate & "," & CLng(Me.RecipeID) & " )", dbFailOnError
...

This creates a new row in the BatchData table correctly except for an incorrect value in BatchData.BatchDate. If I put a breakpoint in and watch this execute, BatchDate will show the value 11/13/2007 however in the table it shows 12:00:36 AM. It's like a type conversion is going on except that BatchDate is a Date and BatchData.BatchDate is defined in the table as a Date/Time. Can someone explain what's going on? Thanks.

_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
In the table, what is the FORMAT of the Date/Time field type? This is down below in the design view of the table. Maybe it's set to LONG TIME instead of like SHORT DATE?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Code:
Dim BatchDate As Date
...
    BatchDate = Date
    db.Execute "INSERT INTO BatchData (BatchDate,RecipeID) VALUES ([COLOR=red]#[/color]" & BatchDate  "[COLOR=red] "#[/color] ," & CLng(Me.RecipeID) & " )", dbFailOnError
...
 
GingerR, forgot to mention that I had manually entered dates that showed fine.

pwise, encasing it in #'s to make a date literal did the job.

_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top