vba to change region Format (1 Viewer)

rvsebi

Registered User.
Local time
Today, 09:07
Joined
Jun 1, 2015
Messages
77
Hi, anybody can help me with vba code to change regional Format ? For example i want to put on load event of first form to change regional format of computer to Romanian, because the program is made to use all week days name in romanian.
Thank you!
 

static

Registered User.
Local time
Today, 07:07
Joined
Nov 2, 2015
Messages
823
You don't change user settings unless you want to be hated.

It's easy enough to create your own translator.

Code:
Sub eg()
    Debug.Print "today is " & DayName & " which is " & DayName(romanian) & " in romanian and " & DayName(french) & " in french"
    Debug.Print "tomorrow is " & DayName(, vbSaturday) & " which is " & DayName(romanian, vbSaturday) & " in romanian and " & DayName(french, vbSaturday) & " in french"
End Sub

Code:
Public Enum region
    french = 1
    german = 2
    romanian = 3
End Enum

Function DayName(Optional lang As region, Optional DayNo As VbDayOfWeek)
    If DayNo = 0 Then DayNo = Weekday(Date,vbsunday)
    
    If lang = 0 Then
        DayName = WeekdayName(DayNo, , vbSunday)
        Exit Function
    End If
    
    Select Case lang
        Case german
            Select Case DayNo
                Case vbMonday:      DayName = "Montag"
                Case vbTuesday:     DayName = "Dienstag"
                Case vbWednesday:   DayName = "Mittwoch"
                Case vbThursday:    DayName = "Donnerstag"
                Case vbFriday:      DayName = "Freitag"
                Case vbSaturday:    DayName = "Samstag"
                Case vbSunday:      DayName = "Sonntag"
            End Select
        Case french
            Select Case DayNo
                Case vbMonday:      DayName = "lundi"
                Case vbTuesday:     DayName = "mardi"
                Case vbWednesday:   DayName = "mercredi"
                Case vbThursday:    DayName = "jeudi"
                Case vbFriday:      DayName = "vendredi"
                Case vbSaturday:    DayName = "samedi"
                Case vbSunday:      DayName = "dimanche"
            End Select
        Case romanian
            Select Case DayNo
                Case vbMonday:      DayName = "Luni"
                Case vbTuesday:     DayName = "Marti"
                Case vbWednesday:   DayName = "Miercuri"
                Case vbThursday:    DayName = "Joi"
                Case vbFriday:      DayName = "Vineri"
                Case vbSaturday:    DayName = "Sâmbata"
                Case vbSunday:      DayName = "Duminica"
            End Select
    End Select
End Function
 

rvsebi

Registered User.
Local time
Today, 09:07
Joined
Jun 1, 2015
Messages
77
Thank You static, but i still need to change region format Country to Romania.
 

rvsebi

Registered User.
Local time
Today, 09:07
Joined
Jun 1, 2015
Messages
77
Nobody know to change region format country ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:07
Joined
May 7, 2009
Messages
19,233
I admit, i dont know.
there are several sites
that uses API calls,
but when I tested it
nothing happens.

I might be thinking, maybe
I need to install the corresponding
Languange Pack to my Office and Windows for
it to work.

Maybe somebody will give you
a working solution.
 

moke123

AWF VIP
Local time
Today, 02:07
Joined
Jan 11, 2013
Messages
3,916
I'm with Static on this one
You don't change user settings unless you want to be hated.
One would think if your writing for a romanian audience they would already have that as a regional setting. I would be inclined to avoid an app that changes the settings on my computer. If you've ever had a program that changes your screen resolution I'm sure you know what I'm talking about.
 

Lightwave

Ad astra
Local time
Today, 07:07
Joined
Sep 27, 2004
Messages
1,521
Arnelgp is correct you can use the Windows API to switch the Operating Systems to different regional formats. Swtiching can be done through VBA from within MS Access no problem. He is also correct that you have to have your Windows version configured for the required regions you wish to switch between.

with Windows 7 (for someone from the uk) you may require the ultimate version of the OS and then you have to ensure that the required language pack is installed - if you are from eastern europe its probable that win 7 will have local regional support (unless computers were brought in from outside your country) - happy to say that Win 8 has language support as standard for everyone although you may need to specifically request certain regional input options within the settings. Windows 10 is similar, language support is free for everyone although it is likely you will have to specifically configure languages if there is more than one. My environment when I first solved this was Windows 7 ultimate. Last time I looked eastern european countries tended to be configured for the local language and dialect as standard + english. It is possible to have as many languages as you like configured to the OS. For most MS OS versions you press alt and shift to switch between regional formats but this can be configured to be triggered by different key strokes. Win 10 gives a three letter indication in the status of which region your system is presently switched to for me I switch between ENG and PYC. If you are from Eastern Europe you probably know all about this and your users are probably constantly switching between local and english formats.

Firstly place the following in a module (note no end function required)

Code:
Public Declare Function ActivateKeyboardLayout Lib "user32.dll" (ByVal myLanguage As Long, Flag As Boolean) As Long 'define your desired keyboardlanguage

Then you can call the function from any form event.
Eg on field GotFocus and LostFocus

I think the code for Romanian is 1048

Code:
'1049 Russian keyboard language layout
'2057 English(United Kingdom)keyboard language layout
'1033 English (United States) keyboard language layout

Private Sub A_GotFocus()
Call ActivateKeyboardLayout(1049, 0)
End Sub

Private Sub A_LostFocus()
Call ActivateKeyboardLayout(2057, 0)
End Sub

You can find the LCID decimal codes here
https://msdn.microsoft.com/en-us/library/ms912047(v=winembedded.10).aspx

Bear in mind this is changing the region for your OS and not your application. So you want to be careful how you turn it on and off and when you turn it on and off - but with a bit of care works great.
 
Last edited:

Users who are viewing this thread

Top Bottom