I know the issue has been brought up, but I have developed code to search on the main form, but what do I need to change to have the code search the subform?
My mainform is named 'Accounts', my subform that I want to search in is called 'ClientInformation Subform.' And the [Last Name] field is in 'ClientInformation Subform'.
My mainform is named 'Accounts', my subform that I want to search in is called 'ClientInformation Subform.' And the [Last Name] field is in 'ClientInformation Subform'.
Code:
Private Sub btnSearchAccounts_Click()
Dim strWhere As String ' The Criteria String
Dim lngLen As Long ' Length of the criteria string to append to
' Adds LIKE Last Name field match to the string
If Not IsNull(Me.txtSearchLast) Then
strWhere = strWhere & " ([Last Name] Like '" & Me.txtSearchLast & "*') AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "Please try again.", vbInformation, "Invalid Search Criterion"
Else
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere
' Apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
Last edited: