For or while loop thru records

yippie_ky_yay

Registered User.
Local time
Yesterday, 23:40
Joined
Jul 30, 2002
Messages
338
Hello forum,

I am obviously still confused with the whole ADO/DAO thing! For this experiment, I'm trying to loop through all the records in my tblPersonal table and display the message "Hey" for each record.

Looking through this forum I always see references to the DAO type (I do know about registering the library). Something always fails on me though. I tried:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim x As Integer

Set db = currentdb

For x = 1 To rs.RecordCount
MsgBox ("Hey")
Next x
End Sub
(this code is tied to a clickable button on a form - the recordsource for the form is all the records from tblPersonal).

I get: "Object variable or With block variable not set" to anything I try placing after "rs."

Anything obvious I'm doing wrong? Is there a reason all examples I've found on this subject have been in DAO?

Thanks in advance,

-Sean
 
Try putting this after the Set db = CurrentDb

Set rs = db.OpenRecordset("TableName",dbOpenTable)


Also remeber to set db & rs to Nothing at the end of your code otherwise you will run into problems later.

ie Set db = Nothing
Set rs = Nothing
 
Last edited:
Thanks Nero - that solved it!

-Sean
 
Last edited:

Users who are viewing this thread

Back
Top Bottom