Problem with date variable

babu

Registered User.
Local time
Today, 10:33
Joined
Jul 10, 2008
Messages
12
Hi All,
I am having a peculier problem. I have declared a variable as say
Dim strRunDate As Date

and assigning it as :
strRunDate = Format(Me.txtDate.Value, "dd/mm/yy")

when i am running this,
the initail value for strRunDate is showing as : 12:00:00 am.

and after executing the assignment statement,
if the value for Me.txtDate.Value is 27/08/2008 then it's showing the value 08/08/2017 where as it should be as 27/08/2008.
This is an existing cod ein production and in teh production version from other's machine it's working fine. When i am copying that version to my m/c, i am getting this problem.

I am getting no clue to this problem.
Please can any one advice me on this.

Many thanks in advance.

Regards,
Babu
 
The problem is due to the fact you have define strRunDate as Date and yet you are using it as if it was a string. Since you have prefixed the name with str it looks like you mean it to be a string. If you mean it to be a date then try something like this

Define the format of Me.txtDate as "Short date" and dont use the the format statement in your code.

strRundate = Me.txtDate

Should fix your problem.
 
Be carefull, if this date is used to read records from a table with a date format, but stored as text, you will not match any records, since date is always date/time no matter what format it is displayed. It is often defined as text instead of date to facilitate the sql search with "Where tableDate = runDate", otherwise the sql would have to be "Where tableDate > rundate - 1 And tableDate < runDate +1". (A field defined as date has the date on the left of the decimal and the time on the right side of the decimal.)
 

Users who are viewing this thread

Back
Top Bottom