ongke0711 > 15-11-17, 09:27 PM
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Public Declare PtrSafe 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 PtrSafe Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
#Else
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 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 GetSystemDefaultLCID Lib "kernel32" () As Long
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
#End If
Public Const LOCALE_ICENTURY = &H24
Public Const LOCALE_ICOUNTRY = &H5
Public Const LOCALE_ICURRDIGITS = &H19
Public Const LOCALE_ICURRENCY = &H1B
Public Const LOCALE_IDATE = &H21
Public Const LOCALE_IDAYLZERO = &H26
Public Const LOCALE_IDEFAULTCODEPAGE = &HB
Public Const LOCALE_IDEFAULTCOUNTRY = &HA
Public Const LOCALE_IDEFAULTLANGUAGE = &H9
Public Const LOCALE_IDIGITS = &H11
Public Const LOCALE_IINTLCURRDIGITS = &H1A
Public Const LOCALE_ILANGUAGE = &H1
Public Const LOCALE_ILDATE = &H22
Public Const LOCALE_ILZERO = &H12
Public Const LOCALE_IMEASURE = &HD
Public Const LOCALE_IMONLZERO = &H27
Public Const LOCALE_INEGCURR = &H1C
Public Const LOCALE_INEGSEPBYSPACE = &H57
Public Const LOCALE_INEGSIGNPOSN = &H53
Public Const LOCALE_INEGSYMPRECEDES = &H56
Public Const LOCALE_IPOSSEPBYSPACE = &H55
Public Const LOCALE_IPOSSIGNPOSN = &H52
Public Const LOCALE_IPOSSYMPRECEDES = &H54
Public Const LOCALE_ITIME = &H23
Public Const LOCALE_ITLZERO = &H25
Public Const LOCALE_NOUSEROVERRIDE = &H80000000
Public Const LOCALE_S1159 = &H28
Public Const LOCALE_S2359 = &H29
Public Const LOCALE_SABBREVCTRYNAME = &H7
Public Const LOCALE_SABBREVDAYNAME1 = &H31
Public Const LOCALE_SABBREVDAYNAME2 = &H32
Public Const LOCALE_SABBREVDAYNAME3 = &H33
Public Const LOCALE_SABBREVDAYNAME4 = &H34
Public Const LOCALE_SABBREVDAYNAME5 = &H35
Public Const LOCALE_SABBREVDAYNAME6 = &H36
Public Const LOCALE_SABBREVDAYNAME7 = &H37
Public Const LOCALE_SABBREVLANGNAME = &H3
Public Const LOCALE_SABBREVMONTHNAME1 = &H44
Public Const LOCALE_SCOUNTRY = &H6
Public Const LOCALE_SCURRENCY = &H14
Public Const LOCALE_SDATE = &H1D
Public Const LOCALE_SDECIMAL = &HE
Public Const LOCALE_SENGCOUNTRY = &H1002
Public Const LOCALE_SENGLANGUAGE = &H1001
Public Const LOCALE_SGROUPING = &H10
Public Const LOCALE_SINTLSYMBOL = &H15
Public Const LOCALE_SLANGUAGE = &H2
Public Const LOCALE_SLIST = &HC
Public Const LOCALE_SLONGDATE = &H20
Public Const LOCALE_SMONDECIMALSEP = &H16
Public Const LOCALE_SMONTHOUSANDSEP = &H17
Public Const LOCALE_SNATIVECTRYNAME = &H8
Public Const LOCALE_SNATIVEDIGITS = &H13
Public Const LOCALE_SNATIVELANGNAME = &H4
Public Const LOCALE_SNEGATIVESIGN = &H51
Public Const LOCALE_SPOSITIVESIGN = &H50
Public Const LOCALE_SSHORTDATE = &H1F
Public Const LOCALE_STHOUSAND = &HF
Public Const LOCALE_STIME = &H1E
Public Const LOCALE_STIMEFORMAT = &H1003
Public Const WM_SETTINGCHANGE = &H1A
Public Const HWND_BROADCAST = &HFFFF&
'Nhap kieu dinh dang Ngay, So
Public Const FormatCurrSymb = "Vnd " 'Ky tu dau cua dang Currency
Public Const FormatDec = "," 'Phan cach so thap phan
Public Const FormatThou = "." 'Phan cach hang ngan
Public Const FormatSDate = "dd-MM-yyyy" 'Kieu Short Date
Public Const FormatLDate = "dd MMMM yyyy" 'Kieu Long Date
Public Sub ChangeSysDatNumCur()
Dim lLocal As Long
Dim LenDate As Long, LenCur As Long, LenNum As Long
Dim dwLCID As Long
Dim BufDate As String * 1024, BufCur As String * 1024, BufNum As String * 1024
On Error GoTo ChangeSysDatNumCur_Error
lLocal = GetSystemDefaultLCID()
LenDate = GetLocaleInfo(lLocal, LOCALE_SSHORTDATE, BufDate, Len(BufDate))
LenCur = GetLocaleInfo(lLocal, LOCALE_SMONTHOUSANDSEP, BufCur, Len(BufCur))
LenNum = GetLocaleInfo(lLocal, LOCALE_STHOUSAND, BufNum, Len(BufNum))
If Not Left$(BufDate, LenDate - 1) = FormatSDate Or Not Left$(BufCur, LenCur - 1) = FormatThou Or Not Left$(BufNum, LenNum - 1) = FormatThou Then 'Kiem tra ngay he thong co cung dinh dang mong muon ko?
dwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, FormatSDate) = False Then 'Thiet lap thu xem co loi ko?
MsgBox "Khong doi duoc dinh dang ngay, so cua he thong.", 64, "Lien he nhan vien Quan tri he thong"
Exit Sub
Else
Change_LocaleInfo
MsgBox "Ung dung se tu khoi dong lai de cac thiet lap co hieu luc.", vbInformation, "Thông báo"
RestartAccessApp.Restart
End If
Else
MsgBox "Dinh dang Ngay/Thang, kieu Tiên te, kieu So phu hop voi ung dung, khong can thiet lap lai." & vbCrLf _
& "- Kieu ngày: " & FormatSDate & vbCrLf _
& "- Kieu so : 1" & FormatThou & "000" & FormatDec & "00", vbInformation, "Chuc mung!"
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, "frmSplash"
Exit Sub
End If
ChangeSysDatNumCur_Error:
MsgBox "Loi khong xac dinh No. " & Err.Number & _
" trong thu tuc [ChangeSysDatNumCur] cua form khoi dong. " _
& vbCrLf & vbCrLf & Err.Description, 64, "Ung dung Access"
End Sub
Sub Change_LocaleInfo()
Dim LCID As Long
LCID = GetSystemDefaultLCID()
'Thiet lap kieu Ngay/Thang
SetLocaleInfo LCID, LOCALE_SLONGDATE, FormatLDate
SetLocaleInfo LCID, LOCALE_SSHORTDATE, FormatSDate
'Thiet lap kieu tien Currency
SetLocaleInfo LCID, LOCALE_SCURRENCY, FormatCurrSymb
SetLocaleInfo LCID, LOCALE_SMONDECIMALSEP, FormatDec
SetLocaleInfo LCID, LOCALE_SMONTHOUSANDSEP, FormatThou
'Thiet lap kieu so Number
SetLocaleInfo LCID, LOCALE_SDECIMAL, FormatDec
SetLocaleInfo LCID, LOCALE_STHOUSAND, FormatThou
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
End Sub
'-----------------------------------------------------------------------------
' Utilities from http://blog.nkadesign.com/microsoft-access/
' (c) Renaud Bompuis, 2008-2009
' Licensed under the Creative Commons Attribution License
' http://creativecommons.org/licenses/by/3.0/
' http://creativecommons.org/licenses/by/3.0/legalcode
'-----------------------------------------------------------------------------
Option Compare Database
Option Explicit
' Time out set to 60 iterations, after which the batch file should delete itself
Private Const TIMEOUT = 60
Public Sub Restart(Optional Compact As Boolean = False)
Dim scriptpath As String
' Construct the full path of our temporary batch file
scriptpath = Application.CurrentProject.FullName & ".dbrestart.bat"
' if the script already exists, then check it isn't an old remnant
' that has passed it's timeout.
If Dir(scriptpath, vbNormal) <> "" Then
If DateAdd("s", TIMEOUT * 2, FileDateTime(scriptpath)) < Date Then
' We've passed twice the batch file timeout, giving ample time for
' it to exectute, so if it's still there, it's most probably a dud
Kill scriptpath
Else
' Timeout hasn't expired beyond the acceptable limit, so it's probably
' still active, just try to close the application again
Application.Quit acQuitSaveAll
Exit Sub
End If
End If
' Construct the batch file
' Note that the TIMEOUT value is only used as a loop counter and
' we do not really count elapsed time in the batch file.
' The ping command takes some time to load and start and even though
' we set its timeout to 100ms, it will take much longer than that to
' execute.
' If we've been asked to comnpact the database, we launch the database
' using the /compact command line switch
Dim s As String
s = s & "SETLOCAL ENABLEDELAYEDEXPANSION" & vbCrLf
s = s & "SET /a counter=0" & vbCrLf
s = s & ":CHECKLOCKFILE" & vbCrLf
s = s & "ping 0.0.0.255 -n 1 -w 100 > nul" & vbCrLf
s = s & "SET /a counter+=1" & vbCrLf
s = s & "IF ""!counter!""==""" & TIMEOUT & """ GOTO CLEANUP" & vbCrLf
s = s & "IF EXIST ""%~f2.%4"" GOTO CHECKLOCKFILE" & vbCrLf
If Compact Then
s = s & """%~f1"" ""%~f2.%3"" /compact" & vbCrLf
End If
s = s & "start "" "" ""%~f2.%3""" & vbCrLf
s = s & ":CLEANUP" & vbCrLf
s = s & "del %0"
' Write batch file
Dim intFile As Integer
intFile = FreeFile()
Open scriptpath For Output As #intFile
Print #intFile, s
Close #intFile
' Create the arguments to be passed to the script
' Here we pass it the full path to the database minus the extension which we pass separately
' this is done so that we can reconstruct the path to the lock file easily in the script.
' The extension to the lock file is also passed as a third argument.
Dim dbname As String, ext As String, lockext As String, accesspath As String
Dim idx As Integer
' Get the path to the msaccess executable, wherever that is
accesspath = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
' Find the extension, starting from the end
For idx = Len(CurrentProject.FullName) To 1 Step -1
If Mid(CurrentProject.FullName, idx, 1) = "." Then Exit For
Next idx
dbname = Left(CurrentProject.FullName, idx - 1)
ext = Mid(CurrentProject.FullName, idx + 1)
' Depending on the database extension, determine its lock file extension
If Left(ext, 2) = "ac" Then
lockext = "laccdb"
Else
lockext = "ldb"
End If
' Call the batch file
s = """" & scriptpath & """ """ & accesspath & """ """ & dbname & """ " & ext & " " & lockext
Shell s, vbHide
' Close our application
Application.Quit acQuitSaveAll
End Sub
vuthaiha90 > 16-11-17, 02:42 PM
Minh Tiên > 09-11-20, 12:24 PM
ongke0711 > 09-11-20, 03:15 PM
(09-11-20, 12:24 PM)Minh Tiên Đã viết: 3. Mình muốn đổi cái List separator từ "," sang ";" luôn thì cần thêm lệnh nào bạn ?
Minh Tiên > 09-11-20, 03:49 PM
ongke0711 > 09-11-20, 05:59 PM
(09-11-20, 03:49 PM)Minh Tiên Đã viết: 2. Vào Control panel thấy đã thay đổi, nhưng hiển thị ngày, tháng, giờ của hệ thống ở góc phải bên dưới mình hình vẫn chưa thay đổi. Tức chưa Apply hệ thống.
Function RefreshExplorer()
Dim strComputer As String
Dim oWMIService As Object, oProcess As Object, colProcess As Object
strComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = oWMIService.ExecQuery("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each oProcess In colProcess
oProcess.Terminate
Next
Set oWMIService = Nothing
Set oProcess = Nothing
Set colProcess = Nothing
End Function
Minh Tiên > 10-11-20, 09:03 AM
Minh Tiên > 10-11-20, 10:27 AM
ongke0711 > 10-11-20, 12:05 PM
(10-11-20, 10:27 AM)Minh Tiên Đã viết: Mình mới sưu tầm được một cách Restart Access bằng cách dùng file RestartDb.vbs (VB Script Script File). Mẫu biên soạn trong File Text đính kèm Demo.
Mình chạy thử trong Win10-64, khởi động lại Access rất nhanh (Khởi động lại, ko nén nên không cần bỏ Chế độ "nén" của Access).
Xin chia sẽ để ACE cùng ngâm cứu !
Minh Tiên > 09-01-21, 02:29 PM