get regional setting - doesn't work

  • Thread starter arista via AccessMonster.com
  • Start date
A

arista via AccessMonster.com

Hi, I have used some code that is recommended here to get a regional setting.
Unfortunatelly it doesn't work properly. It always finds "United Kingdom"
even I change the settings to be different country!
I need this just to display a message when the regional setting is different
from the united kingdom.
Can anybody help pls?

Here is a code which I use:

'const for regional settings
Public Const LOCALE_SENGCOUNTRY As Long = &H1002 'English name of country
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetLocaleInfo Lib "kernel32" _
Alias "GetLocaleInfoA" _
(ByVal Locale As Long, _
ByVal LCType As Long, _
ByVal lpLCData As String, _
ByVal cchData As Long) As Long

Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, ByVal dwLCType As
Long) As String
Dim sReturn As String
Dim r As Long
'call the function passing the Locale type
'variable to retrieve the required size of
'the string buffer needed
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
'if successful..
If r Then
'pad the buffer with spaces
sReturn = Space$(r)
'and call again passing the buffer
r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
'if successful (r > 0)
If r Then
'r holds the size of the string
'including the terminating null
GetUserLocaleInfo = Left$(sReturn, r - 1)
End If
End If
End Function

Private Sub Form_Load()
Dim LCID As Long
Dim xRegionalSet As String
LCID = GetSystemDefaultLCID()
'LOCALE_SENGCOUNTRY Full English name of the country/region. This is
always restricted to characters that can be mapped into the ASCII 127-
character subset.
xRegionalSet = GetUserLocaleInfo(LCID, LOCALE_SENGCOUNTRY)
If (xRegionalSet = "United Kingdom") Then
'nothing
Else
MsgBox "Regional setting isn't set as United Kingdom. It is strongly
adviced to set the regional settings as United Kingdom when using database.
Otherwise some features will not work correctly ! Go to the System ->
Settings -> Regional Settings in your computer system and change the regional
settings country to be United Kingdom.", vbOKOnly, "Regional Setting Problem"
End If
End Sub
 
D

Douglas J. Steele

It may be that your changes aren't being picked up correctly.

To test whether that's the case, try rebooting after you make the change,
then try your code again.

If it works correctly after a reboot, then we can see how you ensure that
the change is picked up correctly without requiring the reboot.
 
A

arista via AccessMonster.com

I rebooted my computer after change of regional settings (to Icelandic) and
it is still the same: xRegionalSet="United Kingdom" during running the code.

Change of the regional setting works immediately both in system and in the
database (I can see eg. French names of months).

So I guess there is some mistake in the code which I do not understand
exactly. It looks for me that the code is not searching for actual regional
setting but returns always one (in this case United Kingdom).

Any idea pls ?
 
D

Douglas J. Steele

Looking a little closer at your code, I don't think you want:

LCID = GetSystemDefaultLCID()

From the name, that would imply that you're going to get the system default,
whereas you want the current user's information.

The code in http://www.mvps.org/access/api/api0017.htm at "The Access Web"
defines constants

Public Const LOCALE_SYSTEM_DEFAULT& = &H800
Public Const LOCALE_USER_DEFAULT& = &H400

and uses LOCALE_USER_DEFAULT when it calls the GetLocaleInfo function.
 

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