If the program is developed using the access database, when the Access database is damaged, the following message will appear as soon as the program is entered:
Can'topendatabase'name'.Itmaynotbeadatabasethatyourapplicationrecognizes,orthefilemaybecorrupt.(Error3049)
If error judgment is not added to the program, the program will interrupt and jump out, which will give the user a very bad impression. To avoid this situation and even prevent the user from discovering that the database is damaged, the following program code must be added to judge. :
PRivateSubForm_Load()
DimdbAsDatabase
OnErrorGoToerror1
Setdb=OpenDatabase("c:/test.mdb")
OnErrorGoTo0
:'Normal program starts
:
ExitSub
error1:
IfErr=3049Then'database is damaged
DBEngine.RepairDatabase"C:/test.mdb"
Resume
Else
MsgBoxErr&Error(Err)
EndIf->