
April 14th, 2005, 08:21 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Posts: 108
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
|
|
Quote: | Originally Posted by sabah i have almost finished a program using access (french version) after i discovered that everytime i enter the date through the form it switches the day and the month in the table i know the problem is because the french date and english date are the opposit
but i dont understand which is english and which is french and what can i do
big confusion
anyone can help  |
You have two options
1- (the best), detect the regional settings configuration and act accordingly
2- change the regional settings configuration to your own (not a good idea, other programs may use the other format).
Code:
Dim LCID As Long, iRet As Long, lpLCDataVar As String, Symbol As String
Dim iRet2 As Long, pos As Integer
Public blnMDSettingsChanged As Boolean
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetThreadLocale Lib "kernel32" () As Long
Private 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
'tablas factor Z
Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const HWND_BROADCAST As Long = &HFFFF&
Private Const WM_SETTINGCHANGE As Long = &H1A
Const LOCALE_SDECIMAL As Long = &HE 'decimal separator
Const LOCALE_STHOUSAND = &HF 'thousand separator
Const LOCALE_SSHORTDATE = &H1F 'short date
Const LOCALE_SCURRENCY = &H14 'currency symbol
Const LOCALE_SMONDECIMALSEP = &H16 ' 'decimal separator for currency
Const LOCALE_SMONTHOUSANDSEP = &H17 'thousand separator for currency
Const old_LOCALE_SDECIMAL As String
Const old_LOCALE_STHOUSAND As String
Const old_LOCALE_SSHORTDATE As String
Const old_LOCALE_SMONTHOUSANDSEP As String
Const old_LOCALE_SMONDECIMALSEP As String
Const old_LOCALE_SCURRENCY As String
Function IsDateFormatRight(CHANGE_ENABLED as boolean,optional DATEFORMAT as string ="dd/MM/yyyy") as boolean
' read short date
LCID = GetUserDefaultLCID()
iRet = GetLocaleInfo(LCID, LOCALE_SSHORTDATE, lpLCDataVar, 0)
Symbol = String$(iRet, 0)
iRet2 = GetLocaleInfo(LCID, LOCALE_SSHORTDATE, Symbol, iRet)
pos = InStr(Symbol, Chr$(0))
If pos > 0 Then
Symbol = Left$(Symbol, pos - 1)
End If
If Symbol <> DATEFORMAT and CHANGE_ENABLED Then
pos = MsgBox("The date's format doesn't match (" & Symbol & ") and could produce system errors." & Chr(13) & "To work properly, is recommended to change the regional options to " & DATEFORMAT & Chr(13) & "Do you acept to make the change?", vbQuestion + vbYesNo, "Configuration")
If pos = vbYes Then
'change thousand separator
blnMDSettingsChanged = True
old_LOCALE_SSHORTDATE = Symbol
LCID = GetUserDefaultLCID()
Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, DATEFORMAT)
Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)
End If
IsDateFormatRight= true
else
IsDateFormatRight= Symbol <> DATEFORMAT
End If
End Function
Public Sub restoreDateSettings()
If old_LOCALE_SSHORTDATE <> vbNullString Then
' restore short date
LCID = GetUserDefaultLCID()
Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, old_LOCALE_SSHORTDATE)
Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)
End If
End Sub
I hope nothing is missing.
|