Full Version: Cycle through records based on some criteria
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
cobrie04
Hello,

Is there a way to cycle through a standard Access form record by record, but only showing the records where one of the fields is equal to a certain value?

I appreciate any and all help!
Larry Larsen
Hi
I'll start at the very basic method and that's base your form on a select query which has some criteria set to = a certain value..
Some further details about your form setup may imply an alternative option..

thumbup.gif
cobrie04
The main purpose of the form is to add records, but I would also like to be able to update existing records. If the person should open the form in Edit Mode, then I would like them to cycle through based on the criteria. Can you base a form on a query that will allow people to edit the records?

Is there a way to have my next button programmed with a loop that will cycle through the records where criteria is met?
Larry Larsen
Hi
You could apply the filter option based on a value.
eg:
CODE
Me.Filter = "[YourFieldName] Like '*" & Me.txtBoxName & "*'"
Me.FilterOn = True

thumbup.gif
cobrie04
Where would I put this code, in the query or in the command button?
Larry Larsen
Hi
Command button on the form, I have seen a small listbox option which has a number of the form controls as values and is used as a filter by method..
thumbup.gif
cobrie04
Hello,

I am pretty new to this stuff, so I am not sure why this is not working. I am getting errors for this code.

I just want to be sure I am asking this correctly.

I want a button that put simply, will go to the next record (where a certain field = 'O'). It will keep going to the very next record that meets the requirements until the end of the record set.

I tried this code on a command button called "next1"? Any ideas how to modify what I have to make it do what I want.... I really appreciate the help.

Private Sub next1_Click()
On Error GoTo Err_next1_Click

Me.Filter = "[banktype] = 'O' "
Me.FilterOn = True
DoCmd.GoToRecord , , acNext

Exit_next1_Click:
Exit Sub

Err_next1_Click:
MsgBox Err.Description
Resume Exit_next1_Click

End Sub
Larry Larsen
Hi Chris
I think your misinterpreting the function of using the filter option, if you code is placed behind an button event it will filter the record source of records to match your criteria.
So all other records will be removed and all you ahve left/showing are records with "[banktype] = 'O' ".
Your code sequence of filtering and moving to the next record just tells it to move on one.
thumbup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.