Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to list every 5th record

Status
Not open for further replies.

CharlieT302

Instructor
Mar 17, 2005
406
US
Hi Everyone,

I have what should be a simple task. Is there an easy way to create a display that lists every 5th or 6th record from a table?

Thanks

 
No easy way I'm aware of, unless you've your own record number.
Keywords: rank (or ranking) modulo

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's one way! It uses the OffSet argument for GoToRecord; this makes acNext or acPrevious move forward or backwards X number of records.

In Form Design View, Goto Properties -- Format and set Navigation Buttons to NO.

Now you'll need to make two custom navigation buttons, call them Go2Next and Go2Prev.

Then use this code:

Code:
Private Sub Form_Open(Cancel As Integer)
  'Set record #5 as the first to show  
  DoCmd.GoToRecord , , acGoTo, 5
End Sub

Private Sub Go2Next_Click()
   'Move forward 5 records 
   DoCmd.GoToRecord , , acNext, 5
End Sub

Private Sub Go2Prev_Click()
    'Move backwards 5 records
    DoCmd.GoToRecord , , acPrevious, 5
End Sub

You may need to do some refining here, such as what you want to do at End of File, but this should be a good start!

Good Luck!


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
This works..... I think.... :)

Add an autonumber field to your table called RecordID.

Create a procedure to loop through all records and check for the results of !RecordID Mod 5. If the result is zero this is a record you need to display so add it to a listbox using the .AddItem method. If the result is > zero do nothing. You'll also need to add the first record every time.

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top