Re: Filter Records with Multiple Combo Boxes
- From: "Dewey" <Dewey@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 23 Dec 2005 08:57:02 -0800
Thanks for the advice TC. Everything seems to work correctly up to the point
where the filter is actually applied - then I get a run-time error.
I left everything the same except the "ReFilter()" procedure, which I
entered as follows (keeping with your example):
Private Sub ReFilter()
Dim s As String
If gThis <> "" Then
s = " AND ([This]= """ & gThis & """)"
Else
If gThat <> "" Then
s = s & " AND ([That]= """ & gThat & """)"
End If
End If
If s = "" Then
Me.FilterOn = False
Else
Me.Filter = Mid$(s, 6)
Me.FilterOn = True
End If
End Sub
I think everything works correctly until the "Me.Filter = Mid$(s, 6)" line.
When I check the value of 's' in the Immediate window just before stepping
into the Me.Filter line, the following is returned:
And ([This]= "selection")
If I check the value of 's' afterwards (just before the Me.FilterOn
execution) the value is still the same as above. Then I get a prompt to
supply a parameter for [This] followed by a run-time error.
Any ideas?
Jason
--
J. Mullenbach
"TC" wrote:
> I'd do it like this. Change the control/field names to suit.
>
> (untested)
>
> ' module level declarations:
> private gThis as string
> private gThat as string
> private gTother as string
>
> Private Sub This_AfterUpdate()
> gThis = trim$(me![This])
> ReFilter
> End Sub
>
> Private Sub That_AfterUpdate()
> gThat = trim$(me![That])
> ReFilter
> End Sub
>
> Private Sub Tother_AfterUpdate()
> gTother = trim$(me![This])
> ReFilter
> End Sub
>
> private sub ReFilter()
> dim s as string
> if gThis <> "" then s = " AND ([This]=""" & gThis & """)"
> if gThat <> "" then s = s & " AND ([That]=""" & gThat & """)"
> if gTother <> "" then s = s & " AND ([Tother]=""" & gTother & """)"
> if s = "" then
> me.filteron = false
> else
> me.filter = mid$( s, 6)
> me.filteron = true
> endif
> end sub
>
> The abivge is a useful technique for building criteria strings when you
> do not know how many of the criteria (if any) have been set. Note how
> even the first string is given a leading " AND ". Thus, if the string s
> is not empty, you know for sure that it starts with the 5 characters "
> AND ", regardless of which criteria were or were not present - so you
> just strip0 those leading characters, and you are left with a proper
> boolean expression for use in the Filter prop.
>
> HTH,
> TC
>
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: Forms and Queries
- Next by Date: How to set References Programmatically?
- Previous by thread: Re: Filter Records with Multiple Combo Boxes
- Next by thread: Re: Filter Records with Multiple Combo Boxes
- Index(es):
Relevant Pages
|