0
我想下面的代碼從訪問數據庫,但獲取錯誤91,請建議如何刪除錯誤。獲取運行時錯誤91 [對象變量或塊變量未設置]
Private Sub CommandButton1_Click()
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConn As String
Set con = New ADODB.Connection
con.Mode = adModeReadWrite
If con.State = adStateClosed Then
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\temp\db2.mdb;Persist Security Info=False;"
con.ConnectionString = strConn
con.Open
End If
Dim startRow As Integer
***Set rs.ActiveConnection = con***
rs.Open "select * from tbl_name"
startRow = 3
Do Until rs.EOF
Cells(startRow, 4) = rs.Fields(0).Value
rs.MoveNext
startRow = startRow + 1
Loop
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub
謝謝喬,現在我明白了..現在它的工作.. – user3103991