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
"Dirk Goldgar" wrote:
[Quoted Text] > "h3llz" <h3llz[ at ]discussions.microsoft.com> wrote in message > news:FE31E5A5-23FE-48CD-A43D-846FE6973842[ at ]microsoft.com... > > 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 > > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) > >
|