I have several buttons on a form that compact different parts of a database. When clicking on them, the program starts making constant error noises and the message bar at the bottom of the browser blinks different errors so fast that you cannot read them. Upon hitting control, alt, delete, I was able to stop the blinking and the sounds and was given the error message "You can't compact the open database while running a macro or Visual Basic code". I've included the code for several of the buttons. Can anyone help?!
'------------------------------------------------------------
' CompactProdFile
'------------------------------------------------------------
Public Function CompactProdFile()
On Error GoTo CompactProdFile_Err
DoCmd.Hourglass True
DoCmd.Echo False, "Now compacting tufting database production data file"
SendKeys "c:\Tuft\prod.mdb~c:\Tuft\prod.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database production data file has been compacted."
DoCmd.Hourglass False
CompactProdFile_Exit:
Exit Function
CompactProdFile_Err:
DoCmd.Echo True
DoCmd.Hourglass False
MsgBox Error$
Resume CompactProdFile_Exit
End Function
'------------------------------------------------------------
' CompactTables
'------------------------------------------------------------
Public Function CompactTables()
On Error GoTo CompactTables_Err
DoCmd.Hourglass True
DoCmd.Echo False, "Now compacting tufting database lookup tables file"
SendKeys "c:\Tuft\tables1.mdb~c:\Tuft\tables1.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database Support data file has been compacted."
DoCmd.Echo False, "Now compacting tufting database employees file"
SendKeys "c:\Tuft\emply.mdb~c:\Tuft\emply.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database employee data file has been compacted."
DoCmd.Hourglass False
CompactTables_Exit:
Exit Function
CompactTables_Err:
DoCmd.Echo True
DoCmd.Hourglass False
MsgBox Error$
Resume CompactTables_Exit
End Function
'------------------------------------------------------------
' CompactProdFile
'------------------------------------------------------------
Public Function CompactProdFile()
On Error GoTo CompactProdFile_Err
DoCmd.Hourglass True
DoCmd.Echo False, "Now compacting tufting database production data file"
SendKeys "c:\Tuft\prod.mdb~c:\Tuft\prod.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database production data file has been compacted."
DoCmd.Hourglass False
CompactProdFile_Exit:
Exit Function
CompactProdFile_Err:
DoCmd.Echo True
DoCmd.Hourglass False
MsgBox Error$
Resume CompactProdFile_Exit
End Function
'------------------------------------------------------------
' CompactTables
'------------------------------------------------------------
Public Function CompactTables()
On Error GoTo CompactTables_Err
DoCmd.Hourglass True
DoCmd.Echo False, "Now compacting tufting database lookup tables file"
SendKeys "c:\Tuft\tables1.mdb~c:\Tuft\tables1.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database Support data file has been compacted."
DoCmd.Echo False, "Now compacting tufting database employees file"
SendKeys "c:\Tuft\emply.mdb~c:\Tuft\emply.mdb~Y", False
DoCmd.RunCommand acCmdCompactDatabase
DoCmd.Echo True, "Tufting database employee data file has been compacted."
DoCmd.Hourglass False
CompactTables_Exit:
Exit Function
CompactTables_Err:
DoCmd.Echo True
DoCmd.Hourglass False
MsgBox Error$
Resume CompactTables_Exit
End Function