使用VB6& ADODB打开访问2000 DB。连接字符串打开。我通过在打开记录集之前获取连接的.STATE来验证这一点。
Private Sub Form_Load()
With conn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Path to database\MyDb.mdb;"
End With
conn.Open
Debug.Print conn.ConnectionString
End Sub
下面的代码段显示了发生错误的行
Private Sub btnGO_Click()
Dim strDbName As String
Dim strg As String
Dim chkr As Variant
Dim MyCnt As Integer
chkr = False
Dim strsql As String
strsql = "Select * from [dbo].[BidItem]"
With rst
.ActiveConnection = conn
.Source = "Select * from [dbo].[BidItem]"
.Open -------------------------------------> Errors at this point
End With
With rst
If Not .EOF And Not .BOF Then
.MoveFirst
MyCnt = .RecordCount
End If
End With
MsgBox ("open")
MsgBox ("Count of TableRows: " & MyCnt)
Set rst = Nothing
End Sub
编辑:确切的错误讯息为Run-Time Error '-2147467259 (80004005)': Could not find file 'C:\Program Files (x86)\Microsoft Visual\VB98\dbo.mdb'
答案 0 :(得分:0)
您的两个代码段都被编码为“私有”,这意味着它们不能很好地共享。 “你去”按钮不清楚实际的“ActiveConnection”在Form加载中的设置是什么。