通用
Dim gcon As ADODB.Connection
这个是连接的FUNCTION
Public Function ConnectDbase(StrConnect As String) As Boolean
On Error GoTo ErrHandle
gcon.ConnectionString = StrConnect
gcon.Open
gcon.CursorLocation = adUseClient
ConnectDbase = True
Exit Function
ErrHandle:
ConnectDbase = False
End Function
然后在FORM_LOAD里调用
Private Sub Form_Load()
Set gcon = New ADODB.Connection
Set rs = New ADODB.Recordset
Dim Pstr As String
Pstr = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;"
Pstr = Pstr & "Data Source=C:\db1.mdb;"
Call ConnectDbase(Pstr)
If ConnectDbase(Pstr) = True Then
MsgBox ("Connected!")
Else
MsgBox ("disConnected!")
End If
End Sub
DATASOURCE肯定是对的
连接的是ACCESS2000
可 MSGBOX 总是显示"disConnected"
咋就不对劲呢?
杂就不对劲呢!
參考答案:Function 不需要用 Call ConnectDbase(Pstr)
把这个去掉 On Error GoTo ErrHandle
就可以看到错误了