Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Filter a form

Experts,

I need to filter a form (split form, data sheet bottom).
cboFilter is unbound
cboPhase is a Value LIst with row source:  "R1";"R2" bound column 1

The below is not correct.  
Do you see the issue?  
Private Sub cboFilter_AfterUpdate()

     If Me.cboFilter & "" = "" Then
        Me.Filter = ""
        Me.FilterOn = False
   Else
        Me.Filter = "[cboPhase] = " & Me.cboFilter
        Me.FilterOn = True
    End If


End Sub

Open in new window



thank you


I had this question after viewing Filter cbo on datasheet -.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

If you filter on text:

Private Sub cboFilter_AfterUpdate()

   If Nz(Me.cboFilter) = "" Then
        Me.Filter = ""
        Me.FilterOn = False
   Else
        Me.Filter = "[cboPhase] = '" & Me.cboFilter & "'"
        Me.FilterOn = True
   End If

End Sub

Open in new window

/gustav
Avatar of pdvsa

ASKER

Hi Gustav,

OK I made the change for text as instructed.
I get this msg box appearing after I enter for example R1 in the unbound cboFilter
I am not sure why I would be getting a msgbox asking for data?
Avatar of pdvsa

ASKER

I see you made a change to code in other areas.  

I don't get a msgbox.

hang on let me test.
Avatar of pdvsa

ASKER

It doesn't seem to filter for what I put in the unbound cboFilter.  (R1 for example)
It does say "filtered" at the bottom of the form but all records appear.

the cboPhase is value list
Avatar of pdvsa

ASKER

Gustav:  have to run for a bit.  will check in after a while.
Put in a line to display your filter value:

Private Sub cboFilter_AfterUpdate()

   If Nz(Me.cboFilter) = "" Then
        Me.Filter = ""
        Me.FilterOn = False
   Else
        MsgBox "Filter: " & "[cboPhase] = '" & Me.cboFilter & "'"
        Me.Filter = "[cboPhase] = '" & Me.cboFilter & "'"
        Me.FilterOn = True
   End If

End Sub

Open in new window

/gustav
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

Rey, that's exactly what my problem was.  I was using the name of the field and not the control source.  

thanks guys....