Radio buttons to filter recrods on a form

B

Bob Richardson

I have an option group with 5 radio buttons (in the header), indicating
different sub groups within my DB. The default button includes ALL records.
I'd like the form to operate this way: When I click a radio button, I want
only those records that meet the button's criteria to be included in the
dataset. When I click another button, a different subset will be used. The
Filter or Query approach works to get the desired subset, but I want to use
a form.

I'm guessing that I want a VBA procedure that would "filter" the DB, and
that this procedure would be triggered by an OnClick (or perhaps
AfterUpdate) event of the OptionGroup (frame) object. Do I save 5 different
Queries and then somehow access one of them depending on some value of the
Frame object?

This is my first DB project so I'm pretty new to all of this. Thanks for
your help.
 
V

Van T. Dinh

The Event you want is the OptionGroup_AfterUpdate Event.

Sample code from one of my apps:

Private Sub fraSelection_AfterUpdate()
'================
' Form_frmNCRSummary.fraSelection_AfterUpdate
'--------
' Purpose:
'--------
' Notes :
'--------
' Parameters:
'
'--------
' Called Subs/Functions
' (none)
'--------
' Calling Subs/Functions
' (none)
'--------
' Returns:
' (none)
'--------
' Author : Van T. Dinh, 10/03/2004
'--------
' Revision History
' Tuesday, 10/03/2004 (VTD): First-coded
'================

On Error GoTo fraSelection_AfterUpdate_Err
With Me
Select Case .fraSelection
Case 1 ' Active NCRs
.Filter = "[DateCompleted] Is Null"
.FilterOn = True
.lblBalance.Visible = True
.lblCompletedDate.Visible = False
.txtBalance.Visible = True
.txtDateCompleted.Visible = False

Case 2 ' Closed NCRs
.Filter = "[DateCompleted] Is Not Null"
.FilterOn = True
.lblBalance.Visible = False
.lblCompletedDate.Visible = True
.txtBalance.Visible = False
.txtDateCompleted.Visible = True

Case 3 ' Active NCRs with Product on hold
.Filter = "[Balance] > 0"
.FilterOn = True
.lblBalance.Visible = True
.lblCompletedDate.Visible = False
.txtBalance.Visible = True
.txtDateCompleted.Visible = False

End Select
End With

fraSelection_AfterUpdate_Exit:
Exit Sub

fraSelection_AfterUpdate_Err:
Select Case Err.Number
Case 0
Case Else
MsgBox "Error " & Err.Number & ": " &
Err.Description & vbCrLf & vbCrLf & _
"(Programmer's note:
Form_frmNCRSummary.fraSelection_AfterUpdate)" & vbCrLf, _
vbOKOnly + vbCritical, "Run-time Error!"
End Select
Resume fraSelection_AfterUpdate_Exit
End Sub

HTH
Van T. Dinh
MVP (Access)
 

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