Combo Box Filter not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there would greatly appreciate any help. Only the last IF statement seems
to activate the Filter on the form from an unbound COmbo Box.
This is what I have so far...

Private Sub FilterByCombo_AfterUpdate()

If Me![FilterByCombo] = "All Open Calls" Then
Me.Filter = Me!CallClosed = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Closed Calls" Then
Me.Filter = Me!CallClosed = True
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Calls to change to RF2" Then
Me.Filter = Me!CallClosed = True And Me.Filter = Me![PartIn?] = True And
Me.Filter = Me!GoodsDespatched = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

End Sub

Maybe there is a simpler way to do this, however I have not figured it out
yet. As you can guess it filters the form by the check box values being true
or false.

Thanks in advance.

Andi
 
You need to assign a string value to the form's Filter property.
The string needs to look like the WHERE clause of a query.

Example:
Me.Filter = "CallClosed = False"
 
Ok that worked but only for the last IF statement in my code.
I tried just having one ENDIF at the end and I get an error saying there is
a block if without an EndIF. However I have an ENDIF

I suppose I could do a Macro instead. One that runs after update with Apply
filters based on these conditions:

[FilterByCombo] = "All Calls Closed"



Allen Browne said:
You need to assign a string value to the form's Filter property.
The string needs to look like the WHERE clause of a query.

Example:
Me.Filter = "CallClosed = False"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Andi Lee Davis said:
Hi there would greatly appreciate any help. Only the last IF statement
seems
to activate the Filter on the form from an unbound COmbo Box.
This is what I have so far...

Private Sub FilterByCombo_AfterUpdate()

If Me![FilterByCombo] = "All Open Calls" Then
Me.Filter = Me!CallClosed = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Closed Calls" Then
Me.Filter = Me!CallClosed = True
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Calls to change to RF2" Then
Me.Filter = Me!CallClosed = True And Me.Filter = Me![PartIn?] = True
And
Me.Filter = Me!GoodsDespatched = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

End Sub

Maybe there is a simpler way to do this, however I have not figured it out
yet. As you can guess it filters the form by the check box values being
true
or false.

Thanks in advance.

Andi
 
Private Sub FilterByCombo_AfterUpdate()

Select Case Me![FilterByCombo] '<== All If Statements refered to the same
control, saves typing and reduces errors

Case "All Open Calls"
Me.Filter = "CallClosed = False"
Me.FilterOn = True

Case "All Closed Calls"
Me.Filter = "CallClosed = True"
Me.FilterOn = True

Case "All Calls to change to RF2"
Me.Filter = "CallClosed = True AND [PartIn?] = True AND GoodsDespatched =
False"
Me.FilterOn = True

Case Else
Me.FilterOn = False
End Select

End Sub

See Filter Property in Help =========================

You can use the Filter property to specify a subset of records to be
displayed when a filter is applied to a form, report query, or table.

Note If you want to specify a server filter within a Microsoft Access
project (.adp) for data located on a server, use the ServerFilter property.

Setting

The Filter property is a string expression consisting of a WHERE clause
without the WHERE keyword. For example, the following Visual Basic code
defines and applies a filter to show only customers from the USA:

Me.Filter = "Country = 'USA'"
Me.FilterOn = True
=========================

Regards John

Andi Lee Davis said:
Ok that worked but only for the last IF statement in my code.
I tried just having one ENDIF at the end and I get an error saying there is
a block if without an EndIF. However I have an ENDIF

I suppose I could do a Macro instead. One that runs after update with Apply
filters based on these conditions:

[FilterByCombo] = "All Calls Closed"



Allen Browne said:
You need to assign a string value to the form's Filter property.
The string needs to look like the WHERE clause of a query.

Example:
Me.Filter = "CallClosed = False"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hi there would greatly appreciate any help. Only the last IF statement
seems
to activate the Filter on the form from an unbound COmbo Box.
This is what I have so far...

Private Sub FilterByCombo_AfterUpdate()

If Me![FilterByCombo] = "All Open Calls" Then
Me.Filter = Me!CallClosed = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Closed Calls" Then
Me.Filter = Me!CallClosed = True
Me.FilterOn = True
Else
Me.FilterOn = False
End If

If Me![FilterByCombo] = "All Calls to change to RF2" Then
Me.Filter = Me!CallClosed = True And Me.Filter = Me![PartIn?] = True
And
Me.Filter = Me!GoodsDespatched = False
Me.FilterOn = True
Else
Me.FilterOn = False
End If

End Sub

Maybe there is a simpler way to do this, however I have not figured it out
yet. As you can guess it filters the form by the check box values being
true
or false.

Thanks in advance.

Andi
 
Back
Top