For Next Counter

  • Thread starter Emir via AccessMonster.com
  • Start date
E

Emir via AccessMonster.com

I want to you use the For....Next where my cnt equals the number of records.
I try to use cnt =
Count() but it only counts 4 records instead of the total 100. What should I
use instead of Count()? Please help.

Dim cnt As Integer
Dim Kounter As Integer
Kounter = 0
DoCmd.GoToRecord , , acFirst

cnt = ????

For Kounter = 1 To cnt
[Codes......]
DoCmd.GoToRecord , , acNext
Next Kounter
 
B

Brendan Reynolds

Emir via AccessMonster.com said:
I want to you use the For....Next where my cnt equals the number of
records.
I try to use cnt =
Count() but it only counts 4 records instead of the total 100. What should
I
use instead of Count()? Please help.

Dim cnt As Integer
Dim Kounter As Integer
Kounter = 0
DoCmd.GoToRecord , , acFirst

cnt = ????

For Kounter = 1 To cnt
[Codes......]
DoCmd.GoToRecord , , acNext
Next Kounter

If you're trying to do something for each record in a form's recordset, you
could do something like ...

For Kounter = 1 to Me.RecordsetClone.RecordCount
...
Next Kounter

Depending on what you're doing with each record, it might be more efficient
to open a recordset or to execute an action query.
 
B

Bob Quintal

I want to you use the For....Next where my cnt equals the number
of records. I try to use cnt =
Count() but it only counts 4 records instead of the total 100.
What should I use instead of Count()? Please help.

Dim cnt As Integer
Dim Kounter As Integer
Kounter = 0
DoCmd.GoToRecord , , acFirst

cnt = ????

For Kounter = 1 To cnt
[Codes......]
DoCmd.GoToRecord , , acNext
Next Kounter

When you open the recordset,
DoCmd.GoToRecord , , acLast
cnt = me.recordset.count
DoCmd.GoToRecord , , acFirst

But a much better approach than a counter is a DO....Loop
Do Until Recordset.EOF
Code:
recordset.movenext
Loop
 
E

Emir via AccessMonster.com

Thank you, Brendan, for the help. It is working the way I wanted it to. I
will try also to use an action query.

Brendan said:
I want to you use the For....Next where my cnt equals the number of
records.
[quoted text clipped - 14 lines]
DoCmd.GoToRecord , , acNext
Next Kounter

If you're trying to do something for each record in a form's recordset, you
could do something like ...

For Kounter = 1 to Me.RecordsetClone.RecordCount
...
Next Kounter

Depending on what you're doing with each record, it might be more efficient
to open a recordset or to execute an action query.
 

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