Do until rst.EOF

S

Scott

I have to loop trough a recordset in my database using the following code:

************************************

Dim rst AS DAO.Recordset
Dim strSQL AS String
strSQL = "Select...My Critarie"
Set rst = CurrentDB.OpenRecordset(strSQL)

Do until rst.EOF
rst.Edit
rst!FieldName = My Entry
rst.Update
rst.MoveNext
loop


*************************************

The problem I have is that when I get the first time to the "Do until
rst.EOF" statement it finds the end of the recordset when in fact the
recodrset has some 35 records, but it shouldn't work this way, it should
loop trough each record in the recordset and do the appropriate updates.

Thanks,

Scott
 
C

Cheryl Fischer

Scott,

Try forcing your recordset to begin with the first record. Insert the
following before the Do Until rst.EOF

rst.MoveFirst

hth,
 
D

Dirk Goldgar

Scott said:
I have to loop trough a recordset in my database using the following
code:

************************************

Dim rst AS DAO.Recordset
Dim strSQL AS String
strSQL = "Select...My Critarie"
Set rst = CurrentDB.OpenRecordset(strSQL)

Do until rst.EOF
rst.Edit
rst!FieldName = My Entry
rst.Update
rst.MoveNext
loop


*************************************

The problem I have is that when I get the first time to the "Do until
rst.EOF" statement it finds the end of the recordset when in fact the
recodrset has some 35 records, but it shouldn't work this way, it
should loop trough each record in the recordset and do the
appropriate updates.

Are you sure that the recordset is not in fact empty? This doesn't look
like your real code, because the capital letters aren't all in the right
places.
 
R

Rick Brandt

Scott said:
I tested in with the SQL statement in the SQL view of a query.

If EOF = True immediately after opening a DAO Recordset then you didn't get
any records returned.

Try a test where you open the Recordset, do a MoveLast, then the command...

MsgBox rst.RercordCount

I would also do a Debug.Print strSQL and try pasting the output into a
query. I suspect that the SQL you *think* you are getting is not what is
actually being produced.
 
S

Scott

Thanks; I found that the recordset was empty, because I used a variable in
the criteria.

Scott
 

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

Similar Threads

Error message on Treeview 1
Invalid Use of Null 3
Make table from recordset 2
Renumber field 8
Recordset too large? 10
Error 3052 MaxLocksPerFile exceeded 2
Read query records 3
OLEDB to 64bit SQL Server 4

Top