run-time error 424 object required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tony6844
    New Member
    • Nov 2008
    • 2

    run-time error 424 object required

    Hi
    I am new at this could someone point me in the right direction
    [CODE=VB]

    Private Sub cmdSearch_Click ()

    If Len(cboSearchFi eld) = 0 Or IsNull(cboSearc hField) = True Then
    MsgBox "You must select a field to search."

    ElseIf Len(txtSearchSt ring) = 0 Or IsNull(txtSearc hString) = True Then
    MsgBox "You must enter a search string."

    Else


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


    Form_frmDVDProg rams1.RecordSou rce = "select * from DVDPrograms where " & GCriteria
    Form_frmDVDProg rams1.Caption = "DVDProgram s (" & cboSearchField. Value & " contains '*" & txtSearchString & "*')"


    DoCmd.Close acForm, "frmSearch"

    MsgBox "Results have been filtered."

    End If

    End Sub

    [/CODE]

    Problem with the line
    [CODE=VB]
    Form_frmDVDProg rams1.RecordSou rce = "select * from DVDPrograms where " & GCriteria
    [/CODE]
    Last edited by Dököll; Nov 17 '08, 03:09 AM. Reason: Code tags...
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    Please check if table DVDPrograms or form Form_frmDVDProg rams exits. It appears that either of them is not found / set in the form.

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      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

      Comment

      • rpicilli
        New Member
        • Aug 2008
        • 77

        #4
        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.

        Code:
        GCriteria = cboSearchField.Value & " LIKE '%" & txtSearchString & "'"
                                              
        or
        
        GCriteria = cboSearchField.Value & " LIKE '" & txtSearchString & "%'"
        
        or 
        
        GCriteria = cboSearchField.Value & " LIKE '%" & txtSearchString & "%'"

        Comment

        • tony6844
          New Member
          • Nov 2008
          • 2

          #5
          Thanks

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

          Tony

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            try using this

            Code:
            GCriteria = cboSearchField.list(cboSearchField.ListIndex) & " LIKE  '%" & txtSearchString & "%'"

            Comment

            • Stewart Ross
              Recognized Expert Moderator Specialist
              • Feb 2008
              • 2545

              #7
              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

              Comment

              Working...