Runtime Error 424 Object Required (1 Viewer)

cgoble

New member
Local time
Today, 05:43
Joined
Jun 15, 2011
Messages
1
Hello I am receiving this error from the Form_AssestsList.RecordSource = "select * from Assests where " & GCriteria line below
Thanks for the help

Curtis
Code:
Option Compare Database
 
Private Sub cmdClose_Click() 'Close form 
   DoCmd.Close 
End Sub
 
Private Sub cmdSearch_Click() 
   If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then 
 
      MsgBox "You must select a field to search." 
 
   ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then 
 
      MsgBox "You must enter a search string." 
 
   Else 
      'Generate search criteria 
       GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'" 'Filter frmCustomers based on search criteria 
 
        Form_AssestsList.RecordSource = "select * from Assests where " & GCriteria 
        Form_AssestsList.Caption = "Assests (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')" 
            'Close frmSearch 
            DoCmd.Close acForm, "frmSearch" 
            MsgBox "Results have been filtered." 
   End If 
End Sub
 
Last edited by a moderator:

boblarson

Smeghead
Local time
Today, 05:43
Joined
Jan 12, 2001
Messages
32,059
First up, don't use syntax using

Form_

it can cause unintended side effects. So, use the forms collection instead:

Forms!AssestsList.RecordSource
 

boblarson

Smeghead
Local time
Today, 05:43
Joined
Jan 12, 2001
Messages
32,059
Second, you might also need to modify this part:

GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"

To something like this:

GCriteria = "[" & cboSearchField.Value & "] LIKE '*" & txtSearchString & "*'"

if any of the fields could have spaces or special characters.
 

Users who are viewing this thread

Top Bottom