By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,967 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,967 IT Pros & Developers. It's quick & easy.

What is wrong with my code??

P: n/a
I am writing code to get a subset of table records, but it is not
looping properly through the fields, it keeps getting stuck in some
sort of infinite loop and I have to be able to walk the whole
recordset.

Am I not using the do loop properly??

dim db as DAO.database
dim rs3 as DAO.recordset
dim strSQL as string
strSQL = "SELECT tblComments.AuditID, tblComments.txtTopic,
tblComments.memAuditTopicComments"
strSQL = strSQL & " FROM tblComments"
strSQL = strSQL & " WHERE tblComments.AuditID=" & lngAuditID
Set rs3 = db.OpenRecordset(strSQL)
rs3.MoveFirst
rs3.MoveLast
Do Until rs3.EOF
'this should show different values, but gets stuck on the value of the
last record
MsgBox rs3.Fields("txtTopic").Value
Loop

I actually need to run a Select Case statement inside the Do loop to
update various records in the recordset, it is a small recordset, <20
records.

Thank you, Tom

Feb 27 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Do Until rs3.EOF
MsgBox rs3.Fields("txtTopic").Value
Loop

Feb 27 '06 #2

P: n/a
rs3.MoveLast moves the current record to the last record of the
recordset so rs3.EOF
is always inmediately true so that's why you get stuck on the value of
the
last record

Try

rs3.MoveFirst
Do Until rs3.EOF
MsgBox rs3.Fields("txtTopic").Value
rs3.moveNext
Loop

Succes

Feb 27 '06 #3

P: n/a
Hello Lyle,
Please excuse me, I cannot see any difference between your suggestion
and my code that I posted above.
Please tell me the difference between what you typed and what I have??
My code gets stuck in an endless loop when it should show 8-10
different values per recordset.
Thank you, Tom

Feb 27 '06 #4

P: n/a
Duh!! MoveNext.
Something simple. :) :) :)
Thank you, Joost.
:) tom

Feb 27 '06 #5

P: n/a
That's because I was stupid.

Feb 27 '06 #6

P: n/a
Hi Tom

Do Until rs3.EOF
MsgBox rs3.Fields("txtTopic").Value

rs3.MoveNext
Loop

You need the 'MoveNext' to move to the next record.

Jeff Pritchard
________________
Asken Research Pty. Ltd.
Access Database Developers
http://www.asken.com.au

"tlyczko" <tl*****@gmail.com> wrote in message
news:11**********************@t39g2000cwt.googlegr oups.com...
I am writing code to get a subset of table records, but it is not
looping properly through the fields, it keeps getting stuck in some
sort of infinite loop and I have to be able to walk the whole
recordset.

Am I not using the do loop properly??

dim db as DAO.database
dim rs3 as DAO.recordset
dim strSQL as string
strSQL = "SELECT tblComments.AuditID, tblComments.txtTopic,
tblComments.memAuditTopicComments"
strSQL = strSQL & " FROM tblComments"
strSQL = strSQL & " WHERE tblComments.AuditID=" & lngAuditID
Set rs3 = db.OpenRecordset(strSQL)
rs3.MoveFirst
rs3.MoveLast
Do Until rs3.EOF
'this should show different values, but gets stuck on the value of the
last record
MsgBox rs3.Fields("txtTopic").Value
Loop

I actually need to run a Select Case statement inside the Do loop to
update various records in the recordset, it is a small recordset, <20
records.

Thank you, Tom

Feb 28 '06 #7

P: n/a
No, I was. :)
I forgot the MoveNext.
Thank you!
:) tom

Feb 28 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.