Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Loops

Geek News

Loops
h3llz 12/10/2008 6:51:02 PM
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?
Re: Loops
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 12/10/2008 7:02:21 PM
"h3llz" <h3llz[ at ]discussions.microsoft.com> wrote in message
news:FE31E5A5-23FE-48CD-A43D-846FE6973842[ at ]microsoft.com...
[Quoted Text]
> 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)

Re: Loops
h3llz 12/10/2008 7:37:02 PM
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)
>
>
Re: Loops
h3llz 12/10/2008 7:40:03 PM
nevermind abotu the .recordcount

"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)
>
>
Re: Loops
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com.invalid> 12/10/2008 7:44:48 PM
"h3llz" <h3llz[ at ]discussions.microsoft.com> wrote in message
news:06632E68-9762-4AE9-8F98-3C949174DCE5[ at ]microsoft.com...
[Quoted Text]
> 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.

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

(please reply to the newsgroup)

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net