Anti-FAQ: W jaki sposób pobrać ustawienia regionalne daty?
Sposób podał Krzysztof Czuryło, poniżej cytuję tekst Krzysztofa w całości:
' (C) by Krzysztof Czuryło 2001
Option Compare Database
Option Explicit
Public Const LOCALE_SSHORTDATE = &H1F
' short date format string
Public Const LOCALE_SLONGDATE = &H20
' long date format string
Public Const WM_SETTINGCHANGE = &H1A
Public Const HWND_BROADCAST = &HFFFFFFFF
Public Const WM_WININICHANGE = &H1A
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 Boolean
Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function AccSetShortDateFormat(DateFormat As String) As Boolean
Dim dwLCID As Long
dwLCID = GetUserDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, DateFormat) = False Then
MsgBox "Failed"
AccSetShortDateFormat = False
Else
SendMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
AccSetShortDateFormat = True
End If
End Function
Public Function AccGetShortDateFormat() As String
Dim dwLCID As Long
Dim lpLCData As String * 100
Dim cchData As Long
dwLCID = GetUserDefaultLCID()
cchData = 100
If GetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, lpLCData, cchData) = False Then
MsgBox "Failed"
Else
AccGetShortDateFormat = Trim(lpLCData)
End If
End Function
Public Function AccSetLongDateFormat(DateFormat As String) As Boolean
Dim dwLCID As Long
dwLCID = GetUserDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SLONGDATE, DateFormat) = False Then
MsgBox "Failed"
AccSetLongDateFormat = False
Else
SendMessage hWndAccessApp, WM_WININICHANGE, 0, 0
AccSetLongDateFormat = True
End If
End Function
Public Function AccGetLongDateFormat() As String
Dim dwLCID As Long
Dim lpLCData As String * 100
Dim cchData As Long
dwLCID = GetUserDefaultLCID()
cchData = 100
If GetLocaleInfo(dwLCID, LOCALE_SLONGDATE, lpLCData, cchData) = False Then
MsgBox "Failed"
Else
AccGetLongDateFormat = Trim(lpLCData)
End If
End Function
Oczywiście używasz funkcji AccSetLongDateFormat()
lub
AccSetShortDateFormat()
.
Np.
AccSetLongDateFormat("dd MMM yyyy")
Możesz też odczytać format. (funkcje AccGet...()
)
+---------------------------------------------+
|lek. Krzysztof Czurylo access(at)krzycz.w.pl |
|www.krzycz.w.pl
|
+---------------------------------------------+