Filter and unfilter subform(datasheet) based on combobox

rheeyum

Registered User.
Local time
Today, 18:43
Joined
Feb 2, 2010
Messages
35
Hi Folks!

I wonder if you could help me out with my problem... I already know how to filter my subform (datasheet) based on a combobox. The problem is, I dont know how can unfilter it... I have a value "ALL" in my combobox so that If I select it, the subform get's unfiltered. I have searched through different threads here but i can't find the unfilter function.. BTW, I am using this code

Code:
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(State) = ComboState"
Me.FilterOn = True
End Sub

The code works pretty well for filtering the subform based on state field but the problem is, I dont have the option to unfilter it. I have already added a value "ALL" and used the code below but to no avail. I know there is some sort of solution or fix to my code... Can you help me out please?


Code:
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(State) = ComboState"
Me.FilterOn = True
If ComboState = ALL Then Me.FilterOn = False
End Sub
 
If ComboState = "ALL" Then Me.FilterOn = False

Do you have a fieldname with brackets? (State)
Or have you just included the brackets unnecessarily?
Special characters should always be avoided in field and object names.
 
Nope, It has no brackets, just state. The code Ive got just shows with a bracket and it was working properly (no debugs). My problem is when I try to choose the field ALL, everything is not shown. It should turn off the filter then
 
Code:
Private Sub Form_Open(Cancel As Integer)
    If ucase(ComboState.value) = "all" Then
        Me.FilterOn = False
    Else
        Me.Filter = "[State] = ComboState"
        Me.FilterOn = True
    End If
End Sub
Try that.
 
thanks man!! I'll try that when I arrived in the office today... whew...
 
Hi Folks!

I wonder if you could help me out with my problem... I already know how to filter my subform (datasheet) based on a combobox. The problem is, I dont know how can unfilter it... I have a value "ALL" in my combobox so that If I select it, the subform get's unfiltered. I have searched through different threads here but i can't find the unfilter function.. BTW, I am using this code

Code:
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(State) = ComboState"
Me.FilterOn = True
End Sub

The code works pretty well for filtering the subform based on state field but the problem is, I dont have the option to unfilter it. I have already added a value "ALL" and used the code below but to no avail. I know there is some sort of solution or fix to my code... Can you help me out please?


Code:
Private Sub Form_Open(Cancel As Integer)
Me.Filter = "(State) = ComboState"
Me.FilterOn = True
[COLOR=red]If ComboState = ALL Then Me.FilterOn = False [/COLOR]
End Sub

Put the Filter Event on your combo After update, because you want to filter the data every time when your combo is updated.

PHP:
Private Sub ComboState_AfterUpdate()
    If (ComboState) = "ALL" Then
        DoCmd.ShowAllRecords
    Else
        DoCmd.ApplyFilter , "State = '" & Me!ComboState & "'"
    End If
End Sub

Always use the DoCmd.ShowAllRecords to remove the filters.
 
Last edited:
waaahhh!!!! The codes still dont work... I had a form with several tabs.. Each tab has its own subform and when I use the code, nothing is filtered and debugs.. It says there was no form or query exist, somthing like that... Can sum1 help?
 
waaahhh!!!! The codes still dont work... I had a form with several tabs.. Each tab has its own subform and when I use the code, nothing is filtered and debugs.. It says there was no form or query exist, somthing like that... Can sum1 help?

Aah so you have the subform there, this why it doest not find the form.

The code is working exactly what it says (on a single form) I tested it.
you have to add some more line in the code, because it seems that your combo is on main form and you want to apply filter on your subform, which is not found by the code, so you have to give the reference of the that subform!field and then it should work.

PHP:
Private Sub ComboState_AfterUpdate()
    If (ComboState) = "ALL" Then
        DoCmd.ShowAllRecords
    Else
        Docmd.gotoCotrol "subformname"
        Forms![FormName]![ContolName].SetFocus
        DoCmd.ApplyFilter , "State = '" & Me!ComboState & "'"
    End If
End Sub

if not then post your db to check where is the bug.
 
Last edited:
Thanks Khalil! Um gonna try that tomorrow in the office and see if it works... Sorry for bugging you,,, I appreciate your help!!!!!!!!! =)
 
waaahhhh.. I am still getting an error. It says sumthing like it is not bound to a column or query...
 

Users who are viewing this thread

Back
Top Bottom