+ Reply to Thread
Results 1 to 2 of 2

Thread: Search code not working

  1. #1
    Registered User
    Join Date
    11-07-2009
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    79

    Search code not working

    Private Sub Command7_Click()
      
        Dim strCriteria As String
      
      If Len(Me.Volume & vbNullString) > 0 Then
        strCriteria = strCriteria & "[Volume] = " & Me.Volume & " AND "
      End If
      
      If Len(Me.Title & vbNullString) > 0 Then
        strCriteria = strCriteria & "[Movie Title] LIKE '*" & Me.Title & "*' AND "
      End If
      
      If Len(Me.Rating & vbNullString) > 0 Then
        strCriteria = strCriteria & "[Rating] = '" & Me.Rating & "' AND "
      End If
      
      If Len(strCriteria) < 1 Then
        MsgBox ("Please enter search criteria before attempting to search the database")
      Else
        strCriteria = Left(strCriteria, Len(strCriteria) - 5)
        If DCount("*", "search", strCriteria) = 0 Then
          MsgBox "No movies matching your search. Please refine your search and try again."
          Exit Sub
        Else
          DoCmd.OpenForm "search results"
        End If
      End If
    
    
        End Sub
    When trying to search for an entry using the volume criteria which is numerical data I get a debug error on the red line of code.
    The error comes up as a "data type mismatch in criteria expression" runtime error 3464

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,259

    Re: Search code not working

    HI,

    After reading your code I have concerns there may be a problem with
    strCriteria = Left(strCriteria, Len(strCriteria) - 5)
    I'd set a breakpoint in my code and insure it is correct before moving forward. You may also need to do a TRIM on strCriteria to knock off the last space or two so it works.

    hope this helps.

    I also wonder why you use " AND " for Volumn but "*' AND " for the others but still remove exactly 5 characters?
    One test is worth a thousand opinions.
    Click the * below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0