I have included this code in ACCESS visual basic but however variable is not defined. I got the code in the forum . thanks
HTML Code:Option Explicit Sub test() Call CompactDatabase("D:\Users\sgg90341\Desktop\ALARM 3 V1.01\RahBreth.accdb") End Sub Public Function CompactDatabase(sDatabasePath As String, Optional BackupBeforeCompactDB As Boolean = False) As Long 'Microsoft Access Library must be added.. Dim strTempFile As String Dim strPathTemp As String Dim strExtention As String Dim strTempF As String strPathTemp = WorksheetFunction.Substitute(sDatabasePath, ".", "|", Len(sDatabasePath) - Len(Replace(sDatabasePath, ".", ""))) strTempFile = Left(sDatabasePath, InStr(1, strPathTemp, "|") - 1) strExtention = "." & Right(sDatabasePath, Len(sDatabasePath) - InStr(1, strPathTemp, "|")) On Error GoTo Err strTempF = strTempFile & "_Temp" & strExtention If BackupBeforeCompactDB = True Then FileCopy sDatabasePath, strTempFile & "_Backup" & strExtention End If Application.DisplayAlerts = False DBEngine.CompactDatabase sDatabasePath, strTempF, dbLangCyrillic Application.DisplayAlerts = True FileCopy strTempF, sDatabasePath Kill strTempF Exit Function Err: CompactDatabase = Err.Number Err.Clear: Exit Function End Function




Reply With Quote
Bookmarks