Need form filtered based on criteria

D

Destin Richter

Hi, I have a main form, based on a table (not a query, and that won't
change). Need code behind a new command button that filters my form such
that any record with the field "Current" (yes/no) set to Yes shows up. Will
make another command button to show No only, and another to remove the filter
(showing all). Can you provide the code I need? Assume tblEmployees and
frmEmployees are components.

Thank you!

Destin Richter
(e-mail address removed)
 
D

Damon Heron

You could certainly use the filter property to do this: put an option group
with three choices on your frmEmployees, calling it frameCurrent, and a
value of 1,2,3 for the options. Have one command button (called cmdFilter in
this example). there should also be a control with the source of "Current"
on the form. (this is untested code, but it should get you started)

Private Sub cmdFilter_Click()
On Error GoTo Err_cmdFilter_Click

select case (Me.frameCurrent.Value)

case 1
me.filter= "[Current]= Yes"
me.filteron=true
case 2
me.filter= "[Current]= No"
me.filteron=true
case 3
me.filteron= false
end select

Exit_cmdFilter_Click:
Exit Sub

Err_cmdFilter_Click:
MsgBox Err.Description
Resume Exit_cmdFilter_Click

End Sub
 

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