Public conn As New ADODB.Connection Public RS As New ADODB.Recordset Public Command As New ADODB.Command '本类适用于access97的数据库 至于2000本人没有试过 '注意在引用本类时要添加引用 Microsoft ActiveX Data Objects 2.5 Library '你可以从<工程>---<引用>然后选取中 Public Function OpenDataBase(DBname As String, PWD As String) As Boolean '打开为True 没打开为False ' 用于打开access数据库 DBname 是数据库名 PWD是数据库的密码 如果没有密码就为空 On Error GoTo toExit '捕捉错误 Dim str As String If conn.State = 0 Then '判断Conn是否已经打开 OpenDataBase = False str = App.Path ' 使数据库的路径为当前目录下 If DBname = "" And UCase$(Right$(DBname, 3)) <> "MDB" Then '这里只是判断是不是access文件你可以自己决定要不要 OpenDataBase = False Else If Right(str, 1) <> "\" Then str = str + "\" End If pstr = "Provider=Microsoft.Jet.OLEDB.3.51;" pstr = pstr & "Persist Security Info=False;" pstr = pstr & "Data Source=" & str & DBname pstr = pstr & ";Jet OLEDB:Database password=" & "'" & PWD & "'" conn.Open pstr ' 打开数据库 OpenDataBase = True End If End If Exit Function toExit: opendatabase = False End Function