try this, create a sub
Sub ApplyFilter()
Dim sFilter As String
sFilter = ""
If Me.txtState <> "" And Not IsNull(Me.txtState) Then
If sFilter = "" Then
sFilter = "[State] Like '*" & Me!txtState & "*'"
Else
sFilter = sFilter & " and [State] Like '*" & Me!txtState & "*'"
End If
End If
If Me.txtCounty <> "" And Not IsNull(Me.txtCounty) Then
If sFilter = "" Then
sFilter = "[County] Like '*" & Me!txtCounty & "*'"
Else
sFilter = sFilter & " And [County] Like '*" & Me!txtCounty & "*'"
End If
End If
If Me.txtCity <> "" And Not IsNull(Me.txtCity) Then
If sFilter = "" Then
sFilter = "[City] Like '*" & Me!txtCity & "*'"
Else
sFilter = sFilter & " And [City] Like '*" & Me!txtCity & "*'"
End If
End If
If Me.txtZip <> "" And Not IsNull(Me.txtZip) Then
If sFilter = "" Then
sFilter = "[Zip] Like '*" & Me!txtZip & "*'"
Else
sFilter = sFilter & " And [Zip] Like '*" & Me!txtZip & "*'"
End If
End If
If Len(sFilter) > 0 Then
Me!SubSearchUSA.Form.Filte
Me!SubSearchUSA.Form.Filte
Else
Me!SubSearchUSA.Form.Filte
Me!SubSearchUSA.Form.Filte
End If
End Sub
then call the sub if the after update of eaxch text box
Private Sub txtstatel_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtcounty_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtcity_AfterUpdate()
ApplyFilter
End Sub
Private Sub txtzip_AfterUpdate()
ApplyFilter
End Sub
but i would prefer more the use of cascading combo boxes,
thus eliminating the typo error from entering the values.
Main Topics
Browse All Topics





by: Jokra_the_BarbarianPosted on 2005-04-03 at 08:14:02ID: 13691871
Make one sub that is run for each of the unbound textbox afterupdate events. Eg:
r = crit rOn = True r = "" rOn = False
Private Sub txtState_AfterUpdate()
Call setFilterCrit()
End Sub
Private Sub txtCounty_AfterUpdate()
Call setFilterCrit()
End Sub
Private Sub txtCity _AfterUpdate()
Call setFilterCrit()
End Sub
Private Sub txtZip_AfterUpdate()
Call setFilterCrit()
End Sub
Private Sub setFilterCrit()
Dim crit as String
crit = ""
If Not IsNull(Me.txtState) then crit = "([State] Like '*" & Me.txtState & "*') AND"
If Not IsNull(Me.txtCounty) then crit = "([County] Like '*" & Me.txtCounty& "*') AND"
If Not IsNull(Me.txtCity ) then crit = "([City] Like '*" & Me.txtCity & "*') AND"
If Not IsNull(Me.txtZip) then crit = "([Zip] Like '*" & Me.txtZip& "*') AND"
If Len(crit) > 0 Then
crit = Mid(crit,1,len(crit)-4)
Me!SubSearchUSA.Form.Filte
Me!SubSearchUSA.Form.Filte
Else
Me!SubSearchUSA.Form.Filte
Me!SubSearchUSA.Form.Filte
End If
End Sub