R
Rocky5
I had this code that worked okay in prior access versions
What do I need to cahnge to make it work in access 2003 and in 2007? See
Below:
also how do I put in a browse button so I can go find it. I have inherited
this code, and I am a beginner.
Is there a way to put a timer on it and make it do it at night when there
are no users in it?
Thank so much in advance
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim dbCodename As Variant
Dim dbdataname As Variant
Dim dbcodebak As Variant
Dim dbdatabak As Variant
dbCodename = "location of database or path to it goes here"
'dbCodename = "P:\92\database\my.mdb"
'dbdataname = "P:\92\database\my_data2000.mdb"
DoEvents
DoCmd.Hourglass True
FileCopy dbCodename, Left(dbCodename, Len(dbCodename) - 3) & "bak"
'FileCopy dbdataname, Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoEvents
DoCmd.Hourglass False
MsgBox " Please wait for Database Repair...", vbQuestion, "Microsoft Access"
DoCmd.Hourglass True
DBEngine.RepairDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak"
'DBEngine.RepairDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoCmd.Hourglass False
MsgBox " Successufully Repaired Database!!" & Chr(13) & " Starting database
Compact now....", vbInformation
DoCmd.Hourglass True
DoEvents
Kill dbCodename
'Kill dbdataname
DoEvents
DBEngine.CompactDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak",
dbCodename
'DBEngine.CompactDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak",
dbdataname
'MsgBox " Compact Completed Successfully@@", vbExclamation, " All Done"
dbcodebak = Left(dbCodename, Len(dbCodename) - 3) & "bak"
'dbdatabak = Left(dbdataname, Len(dbdataname) - 3) & "bak"
Kill dbcodebak
'Kill dbdatabak
DoCmd.Hourglass False
MsgBox " Database Repair and Compact Completed Successfully!!",
vbExclamation, "Operation Complete"
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
What do I need to cahnge to make it work in access 2003 and in 2007? See
Below:
also how do I put in a browse button so I can go find it. I have inherited
this code, and I am a beginner.
Is there a way to put a timer on it and make it do it at night when there
are no users in it?
Thank so much in advance
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim dbCodename As Variant
Dim dbdataname As Variant
Dim dbcodebak As Variant
Dim dbdatabak As Variant
dbCodename = "location of database or path to it goes here"
'dbCodename = "P:\92\database\my.mdb"
'dbdataname = "P:\92\database\my_data2000.mdb"
DoEvents
DoCmd.Hourglass True
FileCopy dbCodename, Left(dbCodename, Len(dbCodename) - 3) & "bak"
'FileCopy dbdataname, Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoEvents
DoCmd.Hourglass False
MsgBox " Please wait for Database Repair...", vbQuestion, "Microsoft Access"
DoCmd.Hourglass True
DBEngine.RepairDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak"
'DBEngine.RepairDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoCmd.Hourglass False
MsgBox " Successufully Repaired Database!!" & Chr(13) & " Starting database
Compact now....", vbInformation
DoCmd.Hourglass True
DoEvents
Kill dbCodename
'Kill dbdataname
DoEvents
DBEngine.CompactDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak",
dbCodename
'DBEngine.CompactDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak",
dbdataname
'MsgBox " Compact Completed Successfully@@", vbExclamation, " All Done"
dbcodebak = Left(dbCodename, Len(dbCodename) - 3) & "bak"
'dbdatabak = Left(dbdataname, Len(dbdataname) - 3) & "bak"
Kill dbcodebak
'Kill dbdatabak
DoCmd.Hourglass False
MsgBox " Database Repair and Compact Completed Successfully!!",
vbExclamation, "Operation Complete"
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub