Loops

  • Thread starter Thread starter h3llz
  • Start date Start date
H

h3llz

Set QryDat = Mydb.OpenRecordset("SELECT * FROM qryBasketContent;")
If QryDat.BOF = False And QryDat.EOF = False Then
QryDat.MoveFirst

how can i loop to get each row ? how can i find out how many records was
returned?
 
h3llz said:
Set QryDat = Mydb.OpenRecordset("SELECT * FROM qryBasketContent;")
If QryDat.BOF = False And QryDat.EOF = False Then
QryDat.MoveFirst

how can i loop to get each row ? how can i find out how many records was
returned?


These lines:
If QryDat.BOF = False And QryDat.EOF = False Then
QryDat.MoveFirst

.... are not necessary in a freshly opened recordset.

To loop through the recordset:

With QryDat

Do Until .EOF

' ... work with current row here ...

' Move to next row.
.MoveNext

Loop

' Display record count, if you want.
MsgBox "Finished processing " & .RecordCount & " records."

.Close ' Close recordset when done with it.

End With

To find out how many records were returned, you have to first move to the
last record. Note that the loop above displays the record count after
looping through all the records. If you want to know right after opening
the recordset, you have to move to the last record first:

Set QryDat = Mydb.OpenRecordset("SELECT * FROM qryBasketContent;")

With QryDat
If Not .EOF Then
.MoveLast ' Go to the end to get record count
.MoveFirst ' Go back to first record, if you want
End If
MsgBox "Finished processing " & .RecordCount & " records."

' ... other code to work with recordset goes here ...

.Close ' Close recordset when done with it.

End With
 
when i use that loop it is wont stop (access crashes) and when i know for a
for certain there should be 2 records, .RecordCount is always 1
 
nevermind abotu the .recordcount

Dirk Goldgar said:
These lines:


.... are not necessary in a freshly opened recordset.

To loop through the recordset:

With QryDat

Do Until .EOF

' ... work with current row here ...

' Move to next row.
.MoveNext

Loop

' Display record count, if you want.
MsgBox "Finished processing " & .RecordCount & " records."

.Close ' Close recordset when done with it.

End With

To find out how many records were returned, you have to first move to the
last record. Note that the loop above displays the record count after
looping through all the records. If you want to know right after opening
the recordset, you have to move to the last record first:

Set QryDat = Mydb.OpenRecordset("SELECT * FROM qryBasketContent;")

With QryDat
If Not .EOF Then
.MoveLast ' Go to the end to get record count
.MoveFirst ' Go back to first record, if you want
End If
MsgBox "Finished processing " & .RecordCount & " records."

' ... other code to work with recordset goes here ...

.Close ' Close recordset when done with it.

End With


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
h3llz said:
when i use that loop it is wont stop (access crashes) and when i know for
a
for certain there should be 2 records, .RecordCount is always 1

Did you try the exact code I posted? I find it hard to believe that code
doesn't terminate normally. Please post the exact code you used.

As for .RecordCount being 1, that will happen if you check it immediately
after opening the recordset, without first navigating to the last record in
the recordset.
 
Back
Top