Looks like you misunderstood...Okay @theDBguy , I pretty much copied what you suggested:
View attachment 90989
Did I take out too much?
Maybe more like this:I should remove the * from - strWhere = strWhere & " AND Odd_Start >= '*" & Me.txtStNum & "*' " ? How would I rewrite that?
Like this?
strWhere = strWhere & " AND Odd_Start >= '*" & Me.txtStNum & ""
strWhere = strWhere & " AND Odd_Start>=" & Nz(Me.txtStNum,0)
Hi. I suppose the next step is for you to post a sample copy of your db with test data, so we can see how you made the search form.Tried it and the form works but it doesn't give results for the street number. I tried many variations of the code but without any luck.
So, I tried another way. Keeping in mind that we are working with numbers at this part of the search.
View attachment 91014
View attachment 91015
This didn't work either but there are no error messages. So, I'm stumped. I feel I'm close but I can't figure it out.
Private Sub cmdSearchStreet_Click()
FilterForm
End Sub
Private Sub Show_All_Click()
Me.FilterOn = False
Dim ctrl As Access.Control
For Each ctrl In Me.Controls
If ctrl.Tag = "filter" Then ctrl = Null
Next ctrl
End Sub
Public Function FilterForm()
Dim fltrStreetName As String
Dim fltrType As String
Dim fltrDirection As String
Dim fltrRange As String
Dim fltrMun
Dim formFilter As String
Dim minStart As String
Dim maxEnd As String
fltrDirection = SqlText(Me.txtDir, "direction")
fltrType = SqlText(Me.txtStType, "Street_Type")
fltrStreetName = SqlText(Me.txtStreet, "Street_Name")
fltrMun = SqlText(Me.txtMun, "Municipality")
If Not (Me.txtStNum & "") = "" Then
If Me.Odd_Start <= Me.Even_Start Then
minStart = "Odd_Start"
Else
minStart = "Even_Start"
End If
If Me.Odd_End >= Me.Even_End Then
maxEnd = "Odd_End"
Else
maxEnd = "Even_End"
End If
fltrRange = minStart & " <= " & Me.txtStNum & " AND " & maxEnd & " >= " & Me.txtStNum
Debug.Print fltrRange
End If
formFilter = CombineFilters(fltrStreetName, fltrDirection, fltrType, fltrMun, fltrRange)
Me.Filter = formFilter
Me.FilterOn = True
End Function
Public Function SqlText(val As Variant, FieldName As String) As String
If (val & "" <> "") Then
SqlText = Replace(val, "'", "''")
SqlText = FieldName & " = '" & SqlText & "'"
End If
End Function
Public Function CombineFilters(ParamArray Filters() As Variant) As String
Dim FilterCombiner As String
Dim i As Integer
Dim strOut As String
FilterCombiner = " AND "
' FilterCombiner = " OR "
For i = 0 To UBound(Filters)
If Filters(i) <> "" Then
If strOut = "" Then
strOut = Filters(i)
Else
strOut = strOut & FilterCombiner & Filters(i)
End If
End If
Next i
CombineFilters = strOut
End Function
It is an interesting method that could work. My concerns are that it could be difficult when sorting through 60000+ records and also finding a street number within the address range. I'd like to test it out to see how easy or difficult it may be for the users.why not just use a Filter buttons.
FYI. The version I provided allows you to easily add more filters
If you want province. Then the code gets added
dim fltrProv as string
fltrProv = SqlText(Me.txtProv, "Province")
Then add to the combiner
formFilter = CombineFilters(fltrStreetName, fltrDirection, fltrType, fltrMun, fltrRange, fltrProv)
Public Function FilterForm()
Dim fltrStreetName As String
Dim fltrType As String
Dim fltrDirection As String
Dim fltrRange As String
Dim fltrMun
Dim formFilter As String
Dim minStart As String
Dim maxEnd As String
...
fltrStreetName = SqlLike(Me.txtStreet, "Street_Name")
...
End Function
Public Function SqlLike(val As Variant, FieldName As String) As String
If (val & "" <> "") Then
SqlLike = Replace(val, "'", "''")
SqlLike = FieldName & " Like '*" & SqlLike & "*'"
Debug.Print SqlLike
End If
End Function
Here is a 6k FAYT example and it is pretty instantaneous. This is not something you would do on a non Access BE. This is an example of a listbox, but you can have a combo do the same.