a simple question on ADODB

J

joyo

I am new to the ADODB, below is my code. It is pretty easy and simple
code, but I don't know why I just keep getting the error message.

Private Sub Form_Load()
Dim cnn As ADODB.Connection
Dim cust As ADODB.Recordset
Set cnn = CurrentProject.Connection
cust.Open "SELECT * FROM tbl_TmpTblInfor", cnn
Do Until cust.EOF
Debug.Print cust!TblName
cust.MoveNext
Loop

End Sub


The error message is

Runtime error 91,
object variable or with block variable not set.

Your help will be highly appreciated.

Thanks

joyo
 
D

Dirk Goldgar

joyo said:
I am new to the ADODB, below is my code. It is pretty easy and simple
code, but I don't know why I just keep getting the error message.

Private Sub Form_Load()
Dim cnn As ADODB.Connection
Dim cust As ADODB.Recordset
Set cnn = CurrentProject.Connection
cust.Open "SELECT * FROM tbl_TmpTblInfor", cnn
Do Until cust.EOF
Debug.Print cust!TblName
cust.MoveNext
Loop

End Sub


The error message is

Runtime error 91,
object variable or with block variable not set.

Your help will be highly appreciated.

Thanks

joyo

You need to actually create the recordset object before you open it:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top