CDate() and Regional Settings

L

Leif S

In an Access (2003) frame where the user is logging operations progress, I
want to test if the time entered by the user exceeds midnight. If so, the
user should be given a warning. I use the following test:

If Me.operations_to > CDate("1.1.1900 23:59:59") Then
message
End If

The machine I use for developing the app is set up with Eurpean(Norwegian)
date/time format. (The Me.operations_to field is of type smalldatetime
SQLServer). The test executes fine until the app is run from a desktop with
Non-European (US) date format. Then the test fails and kills the app.

Can anyone help me with a workaround or even better - a solution?

/Leif S.
 
M

Marshall Barton

Leif said:
In an Access (2003) frame where the user is logging operations progress, I
want to test if the time entered by the user exceeds midnight. If so, the
user should be given a warning. I use the following test:

If Me.operations_to > CDate("1.1.1900 23:59:59") Then
message
End If

The machine I use for developing the app is set up with Eurpean(Norwegian)
date/time format. (The Me.operations_to field is of type smalldatetime
SQLServer). The test executes fine until the app is run from a desktop with
Non-European (US) date format. Then the test fails and kills the app.

All time values are greater than midnight. It looks like
you are just checking if the hour is greater than 24. That
should be automatic for a DateTime field or even if you just
specify a date type format in the text box's property sheet.
OTOH, you say it works, so I may not have deciphered thing
properly.

In any case you should always code to an unambiguous
date/time format. Since CDate uses the user's settings in
Windows, you can not be sure how it will convert a date or
which separator characters are acceptable. In other words,
when coding a literal value, use the # delimiter:

If Me.operations_to > #1/1/1900 23:59:59# Then
 

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