ghaphis
asked on
Forcing date format with session.LCID
Hello,
I am trying to use VB to force my date format to be DD/MM/YYYY in Access. Some computers we use for data entry will have the session.LCID set to US time (and thus MM/DD/YYYY) and some set to UK time (DD/MM/YYYY). For the purposes of this question, let's just say that we can't change the setting manually in the Control Panel.
I want my field to stay in date/time format unless you have a really easy work-around for using a text field. The main reason is that I need to be able to make date calculations in this database.
I tried the following code into the VB code for my form, but it didn't work:
Sub Setlocale()
Session.lcid = 2057
End Sub
Call Setlocale
Any better ideas of how to achieve this?
JTT
I am trying to use VB to force my date format to be DD/MM/YYYY in Access. Some computers we use for data entry will have the session.LCID set to US time (and thus MM/DD/YYYY) and some set to UK time (DD/MM/YYYY). For the purposes of this question, let's just say that we can't change the setting manually in the Control Panel.
I want my field to stay in date/time format unless you have a really easy work-around for using a text field. The main reason is that I need to be able to make date calculations in this database.
I tried the following code into the VB code for my form, but it didn't work:
Sub Setlocale()
Session.lcid = 2057
End Sub
Call Setlocale
Any better ideas of how to achieve this?
JTT
Does Format(DateVariable,"Gener al Date") do what you want?
ASKER
>Does Format(DateVariable,"Gener al Date") do what you want?
My concern is that when data is entered one some computers, it will be entered as D/M/Y but if the session.lcid is set to US English settings, it will switch it to M/D/Y. At other times, the data will not be switched. This makes it difficult to sort out which dates are in the wrong format. I would rather just set the whole data entry system to UK English settings to ensure that it is all D/M/Y.
>See here
http://msdn.microsoft.com/en-us/library/ms525071(VS.85).aspx
I tried to put the session.LCID = 2057 line in the Form_Load() private sub and in the a sub that runs after clicking a button. In both situations I got a "object required" error message. What am I missing?
My concern is that when data is entered one some computers, it will be entered as D/M/Y but if the session.lcid is set to US English settings, it will switch it to M/D/Y. At other times, the data will not be switched. This makes it difficult to sort out which dates are in the wrong format. I would rather just set the whole data entry system to UK English settings to ensure that it is all D/M/Y.
>See here
http://msdn.microsoft.com/en-us/library/ms525071(VS.85).aspx
I tried to put the session.LCID = 2057 line in the Form_Load() private sub and in the a sub that runs after clicking a button. In both situations I got a "object required" error message. What am I missing?
ASKER
I also see that I could possibly also use:
Thread.CurrentThread.Curre ntCulture = new CultureInfo("en-gb")
or
SetLocale "en-gb"
I'm a beginner coder, so I'm not clear where I'm supposed to put these lines (if they are even correct). Modules vs. class module vs. within the code for a specific form. Ideally I would like these rules to apply to the whole database.
JTT
Thread.CurrentThread.Curre
or
SetLocale "en-gb"
I'm a beginner coder, so I'm not clear where I'm supposed to put these lines (if they are even correct). Modules vs. class module vs. within the code for a specific form. Ideally I would like these rules to apply to the whole database.
JTT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But I would not be able to make date calculations with a string in date format, correct? I need to be able to make calculations.
What kind of calculations?
You can do the calculations within the program with the date held in the Date type variable, then use the Format$ function at the end when you want to actually display the date.
You can do the calculations within the program with the date held in the Date type variable, then use the Format$ function at the end when you want to actually display the date.
http://msdn.microsoft.com/en-us/library/ms525071(VS.85).aspx