Thanks for the reply!
Hello Wayne,
I've posted a link to an image of the relationships for this DB:
Relationships.gif
My thinking was to generate an SQL string for the filter since there are a few fields that an end user could search by... It was mentioned by another person to create an "InnerJoin" between the Main Table and the Address Table to only show records in the Main Table that meet the criteria established in the Search String from the Search From. My problem is that I'm not very familiar with this type of code in order to add it to the Filter Source of the Main Form.
Here's the code I'm currently attempting to get functioning:
CODE:
---------------------------------
Private Sub cmdSearch_Click()
Dim strWhereHydrant As String
strWhereHydrant = ""
' Build a filter string for criteria specified...
If Not IsNothing(Me!AddressNumber) Then
strWhereHydrant = "[AddressNumber] Like " & Chr$(34) & Me!AddressNumber
If Right$(Me!AddressNumber, 1) = "*" Then
strWhereHydrant = strWhereHydrant & Chr$(34)
Else
strWhereHydrant = strWhereHydrant & "*" & Chr$(34)
End If
End If
If Not IsNothing(Me!StreetDirection) Then
If IsNothing(strWhereHydrant) Then
strWhereHydrant = "[StreetDirection] Like " & Chr$(34) & Me!StreetDirection
Else
strWhereHydrant = strWhereHydrant & " AND [StreetDirection] Like " & Chr$(34) & Me!StreetDirection
End If
If Right$(Me!StreetDirection, 1) = "*" Then
strWhereHydrant = strWhereHydrant & Chr$(34)
Else
strWhereHydrant = strWhereHydrant & "*" & Chr$(34)
End If
End If
If Not IsNothing(Me!StreetName) Then
If IsNothing(strWhereHydrant) Then
strWhereHydrant = "[StreetName] Like " & Chr$(34) & Me!StreetName
Else
strWhereHydrant = strWhereHydrant & " AND [StreetName] Like " & Chr$(34) & Me!StreetName
End If
If Right$(Me!StreetName, 1) = "*" Then
strWhereHydrant = strWhereHydrant & Chr$(34)
Else
strWhereHydrant = strWhereHydrant & "*" & Chr$(34)
End If
End If
If Not IsNothing(Me!StreetType) Then
If IsNothing(strWhereHydrant) Then
strWhereHydrant = "[StreetType] Like " & Chr$(34) & Me!StreetType
Else
strWhereHydrant = strWhereHydrant & " AND [StreetType] Like " & Chr$(34) & Me!StreetType
End If
If Right$(Me!StreetType, 1) = "*" Then
strWhereHydrant = strWhereHydrant & Chr$(34)
Else
strWhereHydrant = strWhereHydrant & "*" & Chr$(34)
End If
End If
If Not IsNothing(Me!ComplexName) Then
If IsNothing(strWhereHydrant) Then
strWhereHydrant = "[ComplexName] Like " & Chr$(34) & Me!ComplexName
Else
strWhereHydrant = strWhereHydrant & " AND [ComplexName] Like " & Chr$(34) & Me!ComplexName
End If
If Right$(Me!ComplexName, 1) = "*" Then
strWhereHydrant = strWhereHydrant & Chr$(34)
Else
strWhereHydrant = strWhereHydrant & "*" & Chr$(34)
End If
End If
' If no criteria, then nothing to do!
If IsNothing(strWhereHydrant) Then
MsgBox "You didn't enter any criteria." + vbCr & vbLf + "Please enter Search Information.", _
vbQuestion, " Missing Criteria"
Exit Sub
End If
' Hide myself and turn on Hourglass
Me.Visible = False
DoCmd.Hourglass True
If IsLoaded("frmHydrantsMain") Then ' If Hydrants Main form already open,
' Then just filter it
Forms!frmHydrantsMain.SetFocus
DoCmd.ApplyFilter , strWhereHydrant
If Forms!frmHydrantsMain.RecordsetClone.RecordCount = 0 Then
DoCmd.Hourglass False
MsgBox "No Fire Hydrants meet your criteria", vbExclamation, " Fire Hydrants"
DoCmd.ShowAllRecords
Me.Visible = True
'Exit Sub
End If
End If
' DoCmd.OpenForm FormName:="frmAddresses", WhereCondition:=strWhereHydrant
End Sub
---------------------------------
END CODE