Option Button as Filter

B

briank

In my form (frmMain) I have created option buttons (VendorFilter) that I
would like to use as a filter within the form . . . filtering on [Vendor].
However when I click on any of the four radio buttons I do not see any filter
activity in the form. Any suggestions?

Main form name: frmMain
Option Name: VendorFilter

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
Select Case Me!VendorFilter
Case 1
Me.Filter = [Vendor] = "Company A"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 2
Me.Filter = [Vendor] = "Company B"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 3
Me.Filter = [Vendor] = "Company C"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 4
Me.Filter = [Vendor] Like "*"
Me.FilterOn = False
End Select
End Sub
 
D

Douglas J. Steele

First of all, you're setting the filter incorrectly. It needs to be
something like:

Me.Filter = "[Vendor] = 'Company A'"

Exagerated for clarity, that's


Me.Filter = " [Vendor] = ' Company A ' "

How are you invoking that sub? From the Help file, that event only files
when the user does one of the following:

- Selects Records | Filter | Filter By Form
- Selects Records | Filter | Advanced Filter/Sort
- Clicks Advanced Filter/Sort on the Filter menu while the Filter By Form
widnow is open
 
B

briank

Your suggestion worked! I now have this code under the event: OnCurrent.
However I probably need it somewhere else but my attempt at placing it in
AfterUpdate doesn't seem to work. Any thoughts?

Douglas J. Steele said:
First of all, you're setting the filter incorrectly. It needs to be
something like:

Me.Filter = "[Vendor] = 'Company A'"

Exagerated for clarity, that's


Me.Filter = " [Vendor] = ' Company A ' "

How are you invoking that sub? From the Help file, that event only files
when the user does one of the following:

- Selects Records | Filter | Filter By Form
- Selects Records | Filter | Advanced Filter/Sort
- Clicks Advanced Filter/Sort on the Filter menu while the Filter By Form
widnow is open

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


briank said:
In my form (frmMain) I have created option buttons (VendorFilter) that I
would like to use as a filter within the form . . . filtering on [Vendor].
However when I click on any of the four radio buttons I do not see any
filter
activity in the form. Any suggestions?

Main form name: frmMain
Option Name: VendorFilter

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
Select Case Me!VendorFilter
Case 1
Me.Filter = [Vendor] = "Company A"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 2
Me.Filter = [Vendor] = "Company B"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 3
Me.Filter = [Vendor] = "Company C"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 4
Me.Filter = [Vendor] Like "*"
Me.FilterOn = False
End Select
End Sub
 
D

Douglas J. Steele

Which AfterUpdate event are you trying? It won't be the form's AfterUpdate:
it'll be the AfterUpdate event of the frame that holds the option buttons.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


briank said:
Your suggestion worked! I now have this code under the event: OnCurrent.
However I probably need it somewhere else but my attempt at placing it in
AfterUpdate doesn't seem to work. Any thoughts?

Douglas J. Steele said:
First of all, you're setting the filter incorrectly. It needs to be
something like:

Me.Filter = "[Vendor] = 'Company A'"

Exagerated for clarity, that's


Me.Filter = " [Vendor] = ' Company A ' "

How are you invoking that sub? From the Help file, that event only files
when the user does one of the following:

- Selects Records | Filter | Filter By Form
- Selects Records | Filter | Advanced Filter/Sort
- Clicks Advanced Filter/Sort on the Filter menu while the Filter By Form
widnow is open

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


briank said:
In my form (frmMain) I have created option buttons (VendorFilter) that
I
would like to use as a filter within the form . . . filtering on
[Vendor].
However when I click on any of the four radio buttons I do not see any
filter
activity in the form. Any suggestions?

Main form name: frmMain
Option Name: VendorFilter

Private Sub Form_Filter(Cancel As Integer, FilterType As Integer)
Select Case Me!VendorFilter
Case 1
Me.Filter = [Vendor] = "Company A"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 2
Me.Filter = [Vendor] = "Company B"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 3
Me.Filter = [Vendor] = "Company C"
Me.FilterOn = True
MsgBox "Filter Applied"
Case 4
Me.Filter = [Vendor] Like "*"
Me.FilterOn = False
End Select
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