# Re: mdb会坏掉??(请问如何侦测mdb档是否损坏)

Posted by 纪文和 on July 15, 1999 at 21:37:48:

In Reply to: Re: mdb会坏掉??(请问如何侦测mdb档是否损坏) posted by Shadow on July 15, 1999 at 18:50:21:

: : 我写给 user 的程式都会附上修复资料库的供能, 有二种做法:
: : 1.另外写一支修复程式, 告诉 user 资料库坏掉就执行修复程式, 不过比较不人道就是了.
: : 2.在启动程式时自行判断资料库是否坏掉, 若坏掉就执行 compactdatabase 再开启资料库, 这比较人道, 而且 user 比较没感觉到.

: 请问如何侦测mdb档是否损坏?

使用 on error 错误判断啊, 错误代码是 3049

Can't open database 'name'. It may not be a database that your application recognizes, or the file may be corrupt. (Error 3049)

程式大概如下 (可能要测一下)
Private Sub Command1_Click()
Dim db As Database
On Error GoTo error1
Set db = OpenDatabase("c:\test.mdb")
On Error GoTo 0
: '正常程式开始
:
Exit Sub

error1:

If Err = 3049 Then '资料库损毁
DBEngine.RepairDatabase "C:\test.mdb"
Resume
Else
MsgBox Err & Error(Err)
End If

End Sub

Follow Ups:

- Re: mdb会坏掉??(请问如何侦测mdb档是否损坏) Shadow 14:53:03 7/19/99 (0)