Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can we change the LCID in VBA? (A2K SP3)

    I am running an Access application together with an CJK-character input software. However, the input software forcibly changed my LCID value, and hence changed my date setting among other things. I can access the changed LCID value and retrieve its settings (which doesn't have the date setting that I want), but apparently I can't change the LCID value - I actually want to revert the LCID back to my original setting. Can anyone throw some light on it?

    Plese don't tell me to use the fool-proof method of date input with a calendar display irrespective of LCID setting. I know it but my users find it slow and cumbersome.

  2. #2
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can we change the LCID in VBA? (A2K SP3)

    Okay, I'll bite. What's an LCID? Changing the date/time on your machine is simple.

    Date=Date()+1, for example, with change your machines date to tomorrow. (Both Date() and Time() work both ways (read/write)...Now() is read only).

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can we change the LCID in VBA? (A2K SP3)

    According to the online help for Office XP (I don't have 2000), you can only change the LCID (Locale Identifier) if you have installed the Microsoft Office XP Multilingual User Interface Pack. In that case, the Microsoft Office XP Language Settings dialog displays an extra tab for setting the user interface and help language.

    The registry keys containing the language settings are in HKEY_CURRENT_USERSoftwareMicrosoftOffice10.0Common LanguageResources, but I don't know if changing UILanguage or HelpLanguage is the only thing needed to switch languages. For Office 2000 it would be in ...9.0... instead of ...10.0... Be very careful if you're going to edit the registry directly!

  4. #4
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can we change the LCID in VBA? (A2K SP3)

    Actually I didn't explain the reason why I wanted, if possible, to change the LCID of the system. The CJK-Input program that I ran together with my Access application unceremoniously changed the LCID of my system setting from 1033 to 1028 or 2052, depending on the setup of the CJK-Input program. I used short date format for date entry and the local "official" format is dd-MM-yyyy, and it was set in my Access application. However, the short date format dd-MM-yyyy isn't available under LCID 1028 or 2052, and there is no way I can twist the short date entry format without changing the LCID value. The short date format used by the program was M-d-yyyy (the other format variations all with month appearing first). Furthermore, after using and exiting from the CJK-Input program, I need to manually reset my regional short date setting to dd-MM-yyyy.

    If I can set the LCID value back to 1033, I guess I can set the short date format to dd-MM-yyyy too while leaving the CJK-Input function unaffected.

    I will sure give Hans's suggestion a try.

  5. #5
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can we change the LCID in VBA? (A2K SP3)

    Hans, I checked the values at the registry location you suggested. In my system, there were quite a number of LCID entries, with all 'Off' except 1033 which was shown as 'On'. 1033 is my setting: US English. Then I just executed the CJK-Input program, and checked the registry again. In addition to 1033 which was still stated as 'On', I had another LCID 2052 which was marked as 'On'. But my Regional Settings were already changed, and so was my shortdate format. Exiting from the CJK-Entry program didn't turn the registry entry of 2052 to 'Off', as was expected.

    When I ran my Access application with the CJK-Entry program in memory, and access the system LCID from VBA, the default system LCID was 2052. I tried to change the value to, say 1033, and set the LCID. I failed to reset the LCID. Maybe we are allowed to change the LCID values in VBA.

    Here are the codes I use (the codes aren't original, but modified from codes that I obtained from Internet sites. Sorry I can't remember the name of the sites where these codes were extracted and gave them credits):

    ' Regional Date Settings in VBA
    Public Declare Function GetSystemDefaultLCID Lib "Kernel32" () As Long
    Public Declare Function GetUserDefaultLCID 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 Declare Function SetLocaleInfo Lib "Kernel32" _
    Alias "SetLocaleInfoA" _
    (ByVal locale As Long, _
    ByVal LCTYPE As Long, _
    ByVal lpLCData As String) As Long

    Public Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

    Public Const LOCALE_SENGLANGUAGE As Long = &H1001 ' English name of localized language
    Public Const LOCALE_SSHORTDATE = &H1F ' short date format string
    Public Const LOCALE_ICALENDARTYPE = &H1009 ' Set calendar type to Western
    Public Const HWND_BROADCAST As Long = &HFFFF&
    Public Const WM_SETTINGCHANGE As Long = &H1A

    Private Const strShortDateBaru = "dd/MM/yyyy"
    Private strShortDateAsal As String

    Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, _
    ByVal dwLCType As Long) As String

    Dim strReturn As String
    Dim lngRet As Long

    ' Call the function passing the Locale type variable to retrieve
    ' the required size of the string buffer needed
    lngRet = GetLocaleInfo(dwLocaleID, dwLCType, strReturn, Len(strReturn))

    ' if successful (lngRet > 0)
    If lngRet Then
    strReturn = Space$(lngRet) ' pad the buffer with spaces
    ' and call again passing the buffer
    lngRet = GetLocaleInfo(dwLocaleID, dwLCType, strReturn, Len(strReturn))
    ' if successful (lngRet > 0)
    If lngRet Then
    ' lngRet holds the size of the string including the terminating null
    GetUserLocaleInfo = Left$(strReturn, lngRet - 1)
    End If
    End If

    End Function

    ' Set short date format of system
    Function SetShortDateFormat() As String

    Dim LCID As Long ' Locale ID
    Dim strDateFormat As String
    Dim strLocale As String

    ' LCID = GetUserDefaultLCID()
    LCID = GetSystemDefaultLCID()
    ' Get user's original short date string
    strShortDateAsal = GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)
    ' Set the new short date format
    Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, strShortDateBaru)
    If LCID = 2052 Then
    strLocale = "1033" ' LCID="1033" => English US
    Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, strShortDateBaru)
    End If
    ' To make the change take place through the system immediately
    Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)

    End Function

    ' Reset short date format of system back to original
    Function ResetShortDateFormat() As String

    Dim LCID As Long

    LCID = GetSystemDefaultLCID()
    ' Reset the original short date format
    Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, strShortDateAsal)
    ' To make the change take place through the system immediately
    Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)

    End Function

    Note: Calendar type isn't available for LCID 2052.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •