How to programmatically through VB Code change the system date/time format (1 Viewer)

accesser2003

Registered User.
Local time
Today, 07:52
Joined
Jun 2, 2007
Messages
124
As I get some problems because of the format of date/time of the system. I would like to try to set the format of the date/time of the system once the system try. After the system finish it return the format to its original format.
 

namliam

The Mailman - AWF VIP
Local time
Today, 06:52
Joined
Aug 11, 2003
Messages
11,695
*urm* messing with the computer?? Why??
Why not solve your date/time problem from whatever the computer time is? What is exactly the problem you run into?
 

accesser2003

Registered User.
Local time
Today, 07:52
Joined
Jun 2, 2007
Messages
124
This doesnt help me Mr. namliam. Thanks
 

namliam

The Mailman - AWF VIP
Local time
Today, 06:52
Joined
Aug 11, 2003
Messages
11,695
Well I am trying to help you... What is the problem you run into with the system time?
 

rahulgty

Registered User.
Local time
Yesterday, 21:52
Joined
Aug 27, 2005
Messages
99
Keep this Code in load event of Startup form.

Private Sub Form_Load()

SetSysDate

End Sub
***************************************
Also include the code

Private Sub SetSysDate()
Dim lLocal As Long
Dim Length As Long
Dim dwLCID As Long
Dim Buf As String * 1024

On Error GoTo SetSysDate_Error
lLocal = GetSystemDefaultLCID()
Length = GetLocaleInfo(lLocal, LOCALE_SSHORTDATE, Buf, Len(Buf))
If Not Left$(Buf, Length - 1) = "dd/MM/yyyy" Then

If MsgBox(" Your system date format is " & Left$(Buf, Length - 1) & "." & vbCrLf & vbCrLf & _
"To run this application set it to " & _
"Indian standard date format i.e. dd/MM/yyyy. ", 49) = 1 Then

dwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yyyy") _
= False Then
MsgBox "Failed to set System Date Format.", 64, "Dish Care Centre"
Exit Sub
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

Else
DoCmd.Close , Me.Name
DoCmd.Quit


End If
End If


Exit Sub

SetSysDate_Error:
MsgBox "Unexpected Error No. " & Err.Number & _
" in procedure SetSysDate of Form Main. " _
& vbCrLf & vbCrLf & Err.Description, 64, "Dish Care Centre"
End Sub
***************************************
Also add a module

Option Compare Database

Public Const LOCALE_SSHORTDATE = &H1F
Public Const WM_SETTINGCHANGE = &H1A
'same as the old WM_WININICHANGE
Public Const HWND_BROADCAST = &HFFFF&

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 PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetSystemDefaultLCID 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
 

Banana

split with a cherry atop.
Local time
Yesterday, 21:52
Joined
Sep 1, 2005
Messages
6,318
Aren't you also using SQL server? Why not just do a timestamp in SQL server instead?
 

badal

New member
Local time
Yesterday, 21:52
Joined
Feb 15, 2010
Messages
2
Keep this Code in load event of Startup form.

Private Sub Form_Load()

SetSysDate

End Sub
***************************************
Also include the code

Private Sub SetSysDate()
Dim lLocal As Long
Dim Length As Long
Dim dwLCID As Long
Dim Buf As String * 1024

On Error GoTo SetSysDate_Error
lLocal = GetSystemDefaultLCID()
Length = GetLocaleInfo(lLocal, LOCALE_SSHORTDATE, Buf, Len(Buf))
If Not Left$(Buf, Length - 1) = "dd/MM/yyyy" Then

If MsgBox(" Your system date format is " & Left$(Buf, Length - 1) & "." & vbCrLf & vbCrLf & _
"To run this application set it to " & _
"Indian standard date format i.e. dd/MM/yyyy. ", 49) = 1 Then

dwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yyyy") _
= False Then
MsgBox "Failed to set System Date Format.", 64, "Dish Care Centre"
Exit Sub
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0

Else
DoCmd.Close , Me.Name
DoCmd.Quit


End If
End If


Exit Sub

SetSysDate_Error:
MsgBox "Unexpected Error No. " & Err.Number & _
" in procedure SetSysDate of Form Main. " _
& vbCrLf & vbCrLf & Err.Description, 64, "Dish Care Centre"
End Sub
***************************************
Also add a module

Option Compare Database

Public Const LOCALE_SSHORTDATE = &H1F
Public Const WM_SETTINGCHANGE = &H1A
'same as the old WM_WININICHANGE
Public Const HWND_BROADCAST = &HFFFF&

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 PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetSystemDefaultLCID 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

Thanks - It helped me, i was looking for such code
 

badal

New member
Local time
Yesterday, 21:52
Joined
Feb 15, 2010
Messages
2
Thanks- It helped me, i was looking for such code
 

Users who are viewing this thread

Top Bottom