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!
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
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.
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
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.