Loop not running

E

Eric

Hi,
I am trying to get a simple loop to function when I load a
form. I have it set on the on load function of the form.
For some reason no matter what I do the loop won't run
when I load the form. I have verified the syntax and know
that's not the problem. The weirdest thing is when I use
a Toggle Breakpoint and step through the code on load it
works fine, it goes through the loop without error as it
should. I have tried everything to troubleshoot this
problem including putting message boxes before and after
the loop, all of which output the message. I have tried
to have a module called to run the loop but still it
didn't work. I've also tried to put the loop under all
other kinds of properties such as on timer. The only way
I can get the loop to run is if I make a command button
and put the loop under the on click property. I need this
to be automated in the background, any suggestions on what
I need to do? Here is the loop:

Dim Counter
Counter = Me.CurrentRecord

Do While Counter <= Me.CountofRecords
Me.SampleReceived = True
DoCmd.GoToRecord , , acNext
Counter = Me.CurrentRecord
Loop

Thanks for any help,
Eric
 
S

Sandra Daigle

Hi Eric,

I'm not familiar with a property named "CountOfRecords". If you were using
the RecordCount property I would tell you that the problem is due to the
fact that the RecordCount property is not accurate until Access gets around
to updating it or until it is forced to update it by reaching the end of the
recordset. Regardless, there are better ways of accomplishing your goal
without using this property.

with me.recordsetclone
.movefirst
if not .eof and .bof then
do until .eof
.edit
!Samplereceived=trye
.update
.movenext
next
endif
end with

Depending on the size of the recordset, an even better way to do this would
be to run an update query.

One other note - the following declaration should be followed by a datatype,
otherwise the variable is a variant. Of course if you revise your code you
won't need the declaration at all.

Dim Counter
 
G

Guest

Thank you that worked beautifully, and I finally
understand the me.recordsetclone functionality.
-----Original Message-----
Hi Eric,

I'm not familiar with a property named "CountOfRecords". If you were using
the RecordCount property I would tell you that the problem is due to the
fact that the RecordCount property is not accurate until Access gets around
to updating it or until it is forced to update it by reaching the end of the
recordset. Regardless, there are better ways of accomplishing your goal
without using this property.

with me.recordsetclone
.movefirst
if not .eof and .bof then
do until .eof
.edit
!Samplereceived=trye
.update
.movenext
next
endif
end with

Depending on the size of the recordset, an even better way to do this would
be to run an update query.

One other note - the following declaration should be followed by a datatype,
otherwise the variable is a variant. Of course if you revise your code you
won't need the declaration at all.

Dim Counter
--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hi,
I am trying to get a simple loop to function when I load a
form. I have it set on the on load function of the form.
For some reason no matter what I do the loop won't run
when I load the form. I have verified the syntax and know
that's not the problem. The weirdest thing is when I use
a Toggle Breakpoint and step through the code on load it
works fine, it goes through the loop without error as it
should. I have tried everything to troubleshoot this
problem including putting message boxes before and after
the loop, all of which output the message. I have tried
to have a module called to run the loop but still it
didn't work. I've also tried to put the loop under all
other kinds of properties such as on timer. The only way
I can get the loop to run is if I make a command button
and put the loop under the on click property. I need this
to be automated in the background, any suggestions on what
I need to do? Here is the loop:

Dim Counter
Counter = Me.CurrentRecord

Do While Counter <= Me.CountofRecords
Me.SampleReceived = True
DoCmd.GoToRecord , , acNext
Counter = Me.CurrentRecord
Loop

Thanks for any help,
Eric


.
 

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

Top