Thanks for the reply. The thing is, my code (which is in the main form's unload event & excerpted below) doesn't compact the database per se- it just sets the Auto Compact option to True.
So, the error does not happen until the database subsequently closes and tries to compact. So, it's not a run-time error that I can handle in the event's error handler. Is there a way to handle that type of error? Or alternatively, is there a way to directly compact the database with vba, so that I can catch the error in the event vba?
Also, regarding splitting the database- there's only 2 or 3 people in total who will use this database, and they will almost never end up editing the same record at the same time. Does that make it reasonable to avoid splitting the database, or is it still a horrible idea?
Code:
'Capture current compact counter:
CCounter = DLookup("CompactCounter", "tblAdmin", "ID=1")
'Prompt user when CompactCounter reaches specific value:
If CCounter >= 15 Then
CResponse = MsgBox("It's been a while since you've compacted the database." & Chr(10) & Chr(10) & _
"Compacting can improve the database's performance." & Chr(10) & Chr(10) & _
"Would you like to compact before closing?", vbYesNoCancel, "Compact Database?")
If CResponse = vbYes Then
Application.SetOption "Auto compact", True 'Makes the database automatically compact on close.
NewCCounter = 1 'Reset the compact counter to 1
ElseIf CResponse = vbNo Then
Application.SetOption "Auto compact", False 'Do not compact on close
NewCCounter = 10 'Set the compact counter back to 10
ElseIf CResponse = vbCancel Then
Cancel = True 'Cancel close
End If
Else 'If no compact prompt, add 1 to compact counter:
NewCCounter = CCounter + 1
End If
'Set CompactCounter to new value:
DoCmd.SetWarnings False
Sql1 = "UPDATE [tblAdmin]" _
& " SET CompactCounter=" & NewCCounter _
& " WHERE ID=1;"
DoCmd.RunSQL Sql1
DoCmd.SetWarnings True