I am trying to create a search field in a master form which will filter the results in a subform. My problem is that everytime I try to run the code I get an error time message "run time 424: Object Required." It appears that the reference to the subform as a record source is not correct but I have not been able to find out how to fix the issue. Since I am new at VBA I would appreciate any tips on how to fix the problem. The following is the VBA code that I am trying to use:
Private Sub cmdSearch_Click ()
Dim LSQL As String
Dim LSearchString As String
If Len(txtsearchst ring) = 0 Or IsNull(txtsearc hstring) = True Then
MsgBox "You must enter a search string."
Else
LSearchString = textSearchStrin g
'Filter Resuts based on search string
LSQL = "select * from AI_tbl"
LSQL = LSQL & "where ActionItems LIKE '*" & LSearchString & "*'"
Form_Item_sub.R ecordSource = LSQL
lblTitle.Captio n = "Action Item Details: Filtered by '" & LSearchString & "'"
'Clear search string
txtsearchstring = ""
MsgBox "Results have been filtered. All action items containing " & LSearchString & "."
End If
End Sub
Private Sub cmdSearch_Click ()
Dim LSQL As String
Dim LSearchString As String
If Len(txtsearchst ring) = 0 Or IsNull(txtsearc hstring) = True Then
MsgBox "You must enter a search string."
Else
LSearchString = textSearchStrin g
'Filter Resuts based on search string
LSQL = "select * from AI_tbl"
LSQL = LSQL & "where ActionItems LIKE '*" & LSearchString & "*'"
Form_Item_sub.R ecordSource = LSQL
lblTitle.Captio n = "Action Item Details: Filtered by '" & LSearchString & "'"
'Clear search string
txtsearchstring = ""
MsgBox "Results have been filtered. All action items containing " & LSearchString & "."
End If
End Sub
Comment