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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default date problem

Status
Not open for further replies.

Digsys

Technical User
Jun 27, 2002
170
AU
I am trying to set the default date for a record equal to the date of the previous record. I do this at the afterupdate event and although I have managed to have it work for any other variable, I cannot get it to work for a Date variable. The new value becomes 30/12/1899 etc which is the internal date storage, not formatted for a Short date format I use. I have tried using
Date.defaultvalue = date.value
and Date.defaultvalue = Cdate(date)
I do not get an error, but the date format seems to get lost in the assignment statement. I am desperate for help
Thanks
 
me.dtdate.defaultvalue = "#" & me.dtdate.value &"#"

access likes those pound signs
 
Thanks for your help and I can now set the default date, but there is still a complication. I use the short format, dd/mm/yyyy and when there is no ambiguity, ie. 30/09/2001 the new date displays correctly, but if there is a choice, eg 2/10/2001, then the day and month fields reverse to display it as 10/2/2001. The regional setting for the w2000 system are dd/mm/yyyy. Can you offer any suggestions please ?
 
Hi,
Use the Format function to display the date in whatever format you want.

Me.txtDate = Format(varDate,"dd/mm/yyyy") Hope it helps. Let me know what happens.
With regards,
PGK
 
Thanks for effort PGK, but problem is not solved. It seems that the format shown above works to set the new date = to the previous date, but with the # signs included, it has this peculiarity of interchanging day and month. I have tried forcing the format in the Text box and have set up another control on the form with is controlsource = Format(transDate,"dd/mm/yyyy"), but it seems to ignore this and displays the same peculiarity as the original control that displays the date. Any more ideas??
 
Hi,
Whatever format the date is stored internally, the format function is meant to display that date in the way you specify. So where exactly is your problem?

Is it that the date gets stored worngly or the date doesnot display correctly in the short date format you want? Hope it helps. Let me know what happens.
With regards,
PGK
 
Hi PGK
I have narrowed the problem down to a ridiculous point. It is in the display of the date. If I type 1/11/2001 (for 1st Nov 2001) into the text box, it is stored and redisplayed to look exactly the same. If I set the property default for the Text Box as #1/11/2001#, it also performs corrctly, but if I load the date value using code, ie a push
txtDate = #1/11/2001#, then it displays as 11/1/2001. The month and the Day seem to interchange, and I have tried using the format function,but it seems to be ignored and the month and day are still interchanged. Wierd???. Perhaps it is a default systems setting that I do not know about?. Any ideas??
 
Thanks for your help, I managed to read enough in "Access 2002 Desktop Developers Handbook" to solve the problem. It seems that when you use a date variable as an input to a VBA statement, it assumes the date to be U.S.A (mm/dd/yyyy) and you need to convert your date to this format by modifying the above assignment to be
Me.Date.DefaultValue = "#" & Format(Date, "mm/dd/yyyy") & "#"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top