Connecting Tech Pros Worldwide Forums | Help | Site Map

run-time error 424 object required

Newbie
 
Join Date: Nov 2008
Posts: 2
#1: Nov 16 '08
Hi
I am new at this could someone point me in the right direction
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdSearch_Click()
  3.  
  4.     If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
  5.         MsgBox "You must select a field to search."
  6.  
  7.     ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
  8.         MsgBox "You must enter a search string."
  9.  
  10.     Else
  11.  
  12.  
  13.         GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
  14.  
  15.  
  16.         Form_frmDVDPrograms1.RecordSource = "select * from DVDPrograms where " & GCriteria
  17.         Form_frmDVDPrograms1.Caption = "DVDPrograms (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
  18.  
  19.  
  20.         DoCmd.Close acForm, "frmSearch"
  21.  
  22.         MsgBox "Results have been filtered."
  23.  
  24.     End If
  25.  
  26. End Sub
  27.  
  28.  
Problem with the line
Expand|Select|Wrap|Line Numbers
  1.  Form_frmDVDPrograms1.RecordSource = "select * from DVDPrograms where " & GCriteria
  2.  

smartchap's Avatar
Familiar Sight
 
Join Date: Dec 2007
Location: Lucknow, India
Posts: 194
#2: Nov 17 '08

re: run-time error 424 object required


Please check if table DVDPrograms or form Form_frmDVDPrograms exits. It appears that either of them is not found / set in the form.
lotus18's Avatar
Site Addict
 
Join Date: Nov 2007
Location: Zamboanga City, Philippines
Posts: 861
#3: Nov 17 '08

re: run-time error 424 object required


Double-check if the field is really existing or not. Uhm... Why don't you try to replace the asterisk character (*) with percent sign (%). This is only just a suggestion : ).

Rey Sean
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Posts: 77
#4: Nov 18 '08

re: run-time error 424 object required


Hi there.

The line below is not correct.

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

When you use the LIKE and you desire to get similar words you need to supply the symbol % not *

Your line should be (pick just one) depending what you expect from your query.

Expand|Select|Wrap|Line Numbers
  1. GCriteria = cboSearchField.Value & " LIKE '%" & txtSearchString & "'"
  2.  
  3. or
  4.  
  5. GCriteria = cboSearchField.Value & " LIKE '" & txtSearchString & "%'"
  6.  
  7. or 
  8.  
  9. GCriteria = cboSearchField.Value & " LIKE '%" & txtSearchString & "%'"
  10.  
  11.  
  12.  
Newbie
 
Join Date: Nov 2008
Posts: 2
#5: Nov 23 '08

re: run-time error 424 object required


Thanks for your input but still failing at the same line of code and have tried all your suggestions

Tony
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#6: Nov 23 '08

re: run-time error 424 object required


try using this

Expand|Select|Wrap|Line Numbers
  1. GCriteria = cboSearchField.list(cboSearchField.ListIndex) & " LIKE  '%" & txtSearchString & "%'"
  2.  
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#7: Nov 26 '08

re: run-time error 424 object required


You have not posted the value of GCriteria, which includes the item selected from your combo (your search field names). I would guess these field names have spaces in them. Spaces in the field name within the WHERE part will cause a run-time error unless you use the correct syntax for the DB engine concerned. You don't say what the DB is, so I'll assume it is Jet (Access) for now.

You will need to include the field name in brackets in your SQL string for the syntax to be correct.

GCriteria = "[" & cboSearchField & "] LIKE '*"

If indeed it is the Jet database engine you are accessing then the wildcard character for use with Like is the "*" and not the "%". On the other hand you might be accessing a different DB back-end in which the '%' is the wildcard - we don't know because you have not told us what DB you are using.

-Stewart
Reply


Similar Visual Basic 4 / 5 / 6 bytes