Results 1 to 3 of 3
  1. #1
    shod90 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    134

    Changing Windows format language using vba

    Dear Gents ,
    I need to change windows format language from English to French and do some code then revert back to English , I found a code that maybe do what i need but unfortunately i need someone to explain it for me since um not professional coder yet in VBA


    Code:
    #If VBA7 Then
        Private Declare PtrSafe Function SetThreadLocale Lib "kernel32" _
            (ByVal Locale As Long) As Boolean
        Private Declare PtrSafe Function GetUserDefaultLCID Lib "kernel32" () As Long
        Private Declare PtrSafe Function LocaleNameToLCID Lib "kernel32" _
            (ByVal lpName As LongPtr, dwFlags As Long) As Long
    #Else
        Private Declare Function SetThreadLocale Lib "kernel32" (ByVal Locale As Long) As Boolean
        Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
        Private Declare Function LocaleNameToLCID Lib "kernel32" _
           (ByVal lpName As LongPtr, dwFlags As Long) As Long
    #End If
    
    
    Private Sub Test()
        'Get the locale identifier for French (Canada)
        Dim frCa As Long
        frCa = LocaleNameToLCID(StrPtr("fr-CA"), 0)
        'Make sure there function succeeded.
        If Result = 0 Then
            'Cache the current locale
            Dim userLocale As Long
            userLocale = GetUserDefaultLCID
            'Switch to French (Canada)
            If SetThreadLocale(frCa) Then
                'en français
                '...
                'switch back
                SetThreadLocale userLocale
            End If
        End If
    End Sub
    Attached Thumbnails Attached Thumbnails Screenshot 2020-09-29 093819.png  

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    In a nutshell, everything between the #If and #End If declares API functions so that the rest of the code can use it. If the environment is 64 bit (VB7) they are declared in one fashion. If not, then they are declared for 32 bit. The code sets up variables and gets the current language format value (as a number of type Long) and stores that for later retrieval. It also gets the value for the French locale and uses that to set the language accordingly. If you look through the sub code, you'll see it makes calls to those API (Application Programming Interface) that were declared above. Which version is called was already settled in the #If block.

    HTH
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Rickbale is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    3
    Have a look at the setting at Control Panel > Region and Language > Administrative. you might be able to change it there.


    Regards,
    Rick Bale

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 01-27-2020, 03:45 PM
  2. Windows 10 and short date format.
    By NorwegianSiggy in forum Access
    Replies: 1
    Last Post: 09-04-2015, 01:34 PM
  3. Changing a Field Format
    By lwinford in forum Forms
    Replies: 3
    Last Post: 04-23-2013, 01:18 PM
  4. changing system language via VBA
    By focosi in forum Access
    Replies: 3
    Last Post: 09-25-2011, 10:40 AM
  5. Query changing format
    By John Southern in forum Queries
    Replies: 3
    Last Post: 07-05-2010, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums