Recognizing Last record on a Form

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

How can I tell a macro to cycle through for each record on
a form? My macro runs for the first record on the form,
then advances to the next record, and so on. But when it
gets to the last record BOOM I get error messages because
there is no next record. I've used "until EOF" type
statements when looking at table data but is there a
similar method for forms or will I have to write the data
my form displays to a temporary table, process it, and
then dump the table?
 
You can operate (in VBA) on a form's Recordset object using EOF
property, or you can get the number of records in advance and use a FOR
loop - either way works.

Cheers,
Pavel
 
Hi Mike,

Check out the 'RecordsetClone' function. I use it in
a 'Form Current' subroutine in VBA to determine how many
records I have to work with.
It allows you to setup a clone of the dynaset that you are
using to populate the form. You can then do a move to Last
record, get record Count, and then move to First record.
Put the record count into a public variable and then use
a 'For Next' Loop, using the record count, to run your
routine. (don't forget to close the cloned recordset
after you get the record count and save it.)

Hope this helps, Pete
 
Back
Top