Date format

P

Pietro

Hi,
I want to put a code in the Onload event of my main form to prevent users
who don't have the date format as m/d/yyyy from logging to the database..

How can i show an error message that says that the date format is not
correct if it's not m/d/yyyy?
 
J

Jerry Whittle

Something like this in code should check whether the data format is what you
want:

Debug.Print CStr(Date()) = Format(Date(), "m/d/yyyy")

You could put it into an IF statement.

HOWEVER you will shortly become hated by your users. Why do you want to
enforce this rule this way? Why not use input masks to force users to put the
data in the way you want. Not that it matters as Access actually stored dates
and times as a number and not how it's entered in a Date/Time field.

If you want to see a certain date format on forms and reports, use the
Format function to display dates the way you want.
 
P

Pietro

Hi Jerry ,

I cannot use the property input mask for this purpose as in most cases
users don't put a date or time,but it's automatically picked from the system
settings,so sometimes if find date formatted in Arabic,or formatted as
d/m/yyyy
This causes seriuos problems..
Please advise...
 
J

John W. Vinson

Hi,
I want to put a code in the Onload event of my main form to prevent users
who don't have the date format as m/d/yyyy from logging to the database..

How can i show an error message that says that the date format is not
correct if it's not m/d/yyyy?

Ummm...

WHY?

You can control the date format of all the controls on your Forms or Reports,
independent of the users' system date format.

You can control the interpretation of date entry, independent of the users'
system date format (though there may be a training issue if you unwisely allow
ambiguous formats); if your data entry is constrained to (say) d-mmm-yyyy
format there is no ambiguity in what the user types.

Prohibiting legitimate users from opening your database, just because of a
preferred setting on their computer, is massive overkill.
 
J

John W. Vinson

I cannot use the property input mask for this purpose as in most cases
users don't put a date or time,but it's automatically picked from the system
settings,so sometimes if find date formatted in Arabic,or formatted as
d/m/yyyy

The Date() function will store the current date regardless of the system
settings. It's storing an actual date value, not a formatted text string,
unless you're (unwisely!) storing dates in Text fields.
 

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