Results 1 to 7 of 7
  1. #1
    MarksinMO is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    13

    Unbound search box ... Search using LIKE and OR gives me my message box error

    I have a command button with the code below ... Individually each code get my expected results ... I was trying to combine the two into one using OR ... my end result is the MsgBox error. It's not seeing anything in the unbound text75 box.



    I'm sure this is a missing or extra - quote, apostrophe or parenthesis !!! ... I have tried many different combination and have not hit on the correct combination. Or am I missing something else? Thanks in advance.

    Option Compare Database


    Private Sub Command74_Click()
    On Error GoTo Command74_Click_Err


    'This Works Fine DoCmd.ApplyFilter , "[ID]= " & [Forms]![PrintSelect]![Text75] & ""
    'This Works Fine DoCmd.ApplyFilter "", "[Owner] Like ""*"" & [Forms]![PrintSelect]![Text75] & ""*"""

    The Following Does Not work
    DoCmd.ApplyFilter "", "[ID] = " & [Forms]![PrintSelect]![Text75] & " Or [Owner] Like ""*"" & [Forms]![PrintSelect]![Text75] & ""*"", """



    Command74_Click_Exit:
    Exit Sub


    Command74_Click_Err:
    MsgBox "Enter Criteria in Search Box"
    Resume Command74_Click_Exit


    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I've never used ApplyFilter. I use:

    Me.Filter = "[ID] = " & [Forms]![PrintSelect]![Text75] & " Or [Owner] Like '*" & [Forms]![PrintSelect]![Text75] & "*'"
    Me.FilterOn = True

    If you have an ID to search for, why would you need the Owner criteria?

    Is ID a number field? Is the value of Text75 a number? Why would you also use a number to search Owner field? LIKE operator and wildcard only works with text values.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    MarksinMO is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    13
    If I search ID there are no issues however your code brings up the box below ONE time - the first time I search "LIKE", after I ack OK then it will search for either criteria multiple times with no issues. Close the form and reopen it does the same thing with the text search the first time.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	9 
Size:	6.0 KB 
ID:	22120




    ID is the PK autonumber ... Owner is the generator would need this for reporting purposes ... ID would search for number so = to, Like to search for "like" texts

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    What is 'ter' - I don't have 'ter' in my suggestion.

    What is Text75 - an UNBOUND textbox where user can enter anything for search parameter? If user enters text like "John Doe" the ID criteria will error.

    Need to dynamically build the filter string. Review http://www.allenbrowne.com/ser-62.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    MarksinMO is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    13
    Yes Unbound text box as stated above ... ter is the first three letters for Terry ... an owner of numerous records in the Db ... for the most part the user will enter three to four letters to search for the owners name ... I entered ter in the unbound text75 and the first time it pops up the enter parameter value ... I click OK (I don't have to enter anything) once and it brings up all records that has any form of ter in the field. Terry Waters Carter, etc. Once I click OK the first time I can search for any letter combination with no issues. If i close and reopen the same issue occurs.

    Thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    ID is a number type field. Entering a text value as parameter should cause data type mismatch. Perhaps the popup is related to this issue.

    My point is, cannot have this filter criteria constructed like this. These are two different kinds of fields and they cannot have the same parameter.

    Did you review the referenced link?

    You could have conditional code like:

    If IsNumeric(Me.Text75) Then
    strWHERE = "[ID] = " & Me.Text75
    Else
    strWHERE = "[Owner] Like '*" & Me.Text75 & "*'"
    End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    MarksinMO is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    13
    Ok thanks ... I looked over AB's code and will look to see if I can make sense of it and apply it to my Db ... I have used suggestions from AB several times.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 11-06-2014, 01:15 PM
  2. Unbound Combobox search issue
    By Eliza P in forum Forms
    Replies: 1
    Last Post: 08-18-2014, 12:52 PM
  3. Replies: 2
    Last Post: 11-12-2013, 07:06 PM
  4. Replies: 2
    Last Post: 04-17-2013, 02:12 PM
  5. Replies: 7
    Last Post: 09-21-2012, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums