Date Mask MM/DD/YYYY or DD/MM/YYYY

P

Patrick Graham

Right now the date field appears like this

_ _ / _ _ / _ _ _ _

I would like to have it appear using M D Y according to
the users default settings (either)

MM/DD/YYYY

or

DD/MM/YYYY

Any thoughts?
 
D

Dirk Goldgar

Patrick Graham said:
Right now the date field appears like this

_ _ / _ _ / _ _ _ _

I would like to have it appear using M D Y according to
the users default settings (either)

MM/DD/YYYY

or

DD/MM/YYYY

Any thoughts?

I have thoughts, but I don't think you'll like them. I don't like the
idea of using *any* input mask for a date field. I'd rather let Access
do what it does naturally: let the user enter the date the way they
feel most comfortable with, and then interpret that as a date in
accordance with the user's regional settings.

Are you saying you want to have the literal string MM/DD/YYYY or
DD/MM/YYYY show in the text box? That may prove difficult. You could
presumably find out the user's regional date format by reading the
registry, but getting a different place-holder character to show in
different positions in the input mask ... I don't know that you can do
that.
 
P

Patrick Graham

This came up as a problem cause I sat at someones desk
who had his regions set differently and I entered a date
wrong. So I figured access would be default have this
feature, guess not :)

I suppose I could figure out a work around myself:

My thoughts:
Use the Now() to get the current date.
Covert that to a string.
Then use the various date funcntion to get the month and
the day values.
Then compare those value to that of the string version of
the date.
Where the day lands put a DD, diddo for month and MM.
Default the date control to this thingy, and blank it as
they leave the control (to avoid type error), if the user
does enter anything else in there.


BUT I will put it off for now not a priority. Thanks for
the comment though. Your way might taking more
investigation but certainly less coding.
 
D

Dirk Goldgar

Patrick Graham said:
This came up as a problem cause I sat at someones desk
who had his regions set differently and I entered a date
wrong. So I figured access would be default have this
feature, guess not :)

I suppose I could figure out a work around myself:

My thoughts:
Use the Now() to get the current date.
Covert that to a string.
Then use the various date funcntion to get the month and
the day values.
Then compare those value to that of the string version of
the date.
Where the day lands put a DD, diddo for month and MM.
Default the date control to this thingy, and blank it as
they leave the control (to avoid type error), if the user
does enter anything else in there.

Interesting idea, but I don't think it will work, because the string
"MM/DD/YYYY" is not a valid default value for a control bound to a date.
You could probably do it with an unbound control, though, provided you
are willing to write the extra code to transfer data from record to
control and back again as you move through the form's records or save
updates.

Your proposed method for determining the regional date setting has a
flaw, I think. What happens if the current date is one on which the
month and day numbers are the same? But if you don't want to read the
registry to determine the setting, you could use a variation on your
idea: use a specific date as the basis for comparison instead of the
current date.

An alternative approach to all this might be to determine the date
settings and change the caption of a label by the date control to
specify the desired date format. Or provide separate, labeled text
boxes for the month, day, and year.
 
T

TC

Dirk Goldgar said:
Interesting idea, but I don't think it will work, because the string
"MM/DD/YYYY" is not a valid default value for a control bound to a date.
You could probably do it with an unbound control, though, provided you
are willing to write the extra code to transfer data from record to
control and back again as you move through the form's records or save
updates.

Your proposed method for determining the regional date setting has a
flaw, I think. What happens if the current date is one on which the
month and day numbers are the same? But if you don't want to read the
registry to determine the setting, you could use a variation on your
idea: use a specific date as the basis for comparison instead of the
current date.

An alternative approach to all this might be to determine the date
settings and change the caption of a label by the date control to
specify the desired date format. Or provide separate, labeled text
boxes for the month, day, and year.


To avoid the locale info. APIs, you can just do a default conversion on the
fixed date constant "1/2/3003", then check the day & month numbers of the
resultant date-type value. This tells you whether to use d/m/y, or m/d/y! Of
course, it does assume that the year comes last.

TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top