Results 1 to 11 of 11
  1. #1
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48

    Few Problems : Search Button Form

    Hi! Actually I had a code that the use is, I will search for a multiple data that can be separated by comma.



    For Example : I put [apple, banana] on my textbox(exact as what you see on the []) and I have a record on my database named :
    ♦apple1
    ♦apple2
    ♦apple3
    ♦banana2
    ♦banana1
    ♦carrot1
    ♦carrot2

    and when I press the Search Button it will show me all records that has APPLE and BANANA in the table.

    but the problem of my code is when I put a value on the textbox like BANANA or whatever word it is. It will just filter my 50k+ record into 300records which is surely wrong, because it must show me the record that has BANANA word in the table.

    Here's the code :

    LEGEND :
    • Command26 - Button that I consider as a Search/Filter Button
    • Text24 - Textbox where will I put the value that I'm looking
    • Card_Number - Name of the column where what I' am searching is Located.

    Code:
    Private Sub Command26_Click()
            Dim strFilter As String, strFilters() As String
            Dim intX As Integer
         
            With Me
                strFilters = Split(Nz(.Text24, ""), ",")
                For intX = 0 To UBound(strFilters)
                    strFilter = strFilter & _
                                Replace(" OR ([Card_Number] Like '%F*')", _
                                        "%F", strFilters(intX))
                Next intX
                .Filter = Mid(strFilter, 5)
                .FilterOn = (.Filter > "")
            End With
    End Sub
    I'm still playing on the code, but still I need someones help. Thank you in advanced.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Well, you can use this technique to debug the string and make sure it's coming out properly:

    http://www.baldyweb.com/ImmediateWindow.htm

    If you don't spot the problem, post the result here.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    You state 'show me all records that has APPLE and BANANA in the table'. Do you actually mean 'all records that have either apple OR banana'? It is the OR operator you have in code.

    Your example data of apples and bananas doesn't fit the code which references Card_Number as the search field.

    Why the %F?
    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.

  4. #4
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48
    Hi! Actually I'm not directly looking for apple and banana. Just an example.

    It always filter on 300 records when I put a value on the textbox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    I can't see anything wrong with code. Use debug techniques. Provide project for analysis.
    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.

  6. #6
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48

    Help Search Form

    Hi everyone! I'm working for this project for almost 3 weeks now, and I need to finish it. I had two set of database which has different sets of codes. I want to do this is to search multiple data separated by comma using keyword.

    Like example I have a record of APPLE and BANANA.. when I put [app, bana] on my textbox it will show me all the records that has APPLE and BANANA.

    But this one is for Card_Number please check it. Please help me

    CODE/DB1
    https://www.cx.com/mycx/share/69j4kX...OBtLIg/CSP.zip

    CODE/DB2
    https://www.cx.com/mycx/share/lJRs13...BtLIg/CSP2.zip

    Thank you in advanced.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Need quote marks instead of apostrophes.

    .Filter = Replace(Mid(strFilter, 5), "'", Chr(34))
    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.

  8. #8
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48
    Hi sir June7 It's working now! thank you so much! the search box and button should be placed on the subform.

    But one more thing, i can search using keyword even entering comma but it couldn't search for the next value after the comma?

    like I'm searching [5299671, 5299672] the only record it will show is 5299671+++++ and the 5299672 is not?

  9. #9
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48
    yo yo yo! it works.. i shouldn't put space after the comma

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    That or use Trim function on each array element.
    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.

  11. #11
    spideynok is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    48
    Code:
    Private Sub Command26_Click()
            Dim strFilter As String, strFilters() As String
            Dim intX As Integer
         
            With Me
                strFilters = Split(Nz(.Text24, ""), ",")
                For intX = 0 To UBound(strFilters)
                    strFilter = strFilter & _
                                Replace(" OR ([Card_Number] Like '%F*')", _
                                        "%F", strFilters(intX))
                Next intX
                .Filter = Replace(Mid(strFilter, 5), "'", Chr(34))
                .FilterOn = (.Filter > "")
            End With
    End Sub
    I used this and I place the code on a search button inside the subform. Thank you so much sir!

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

Similar Threads

  1. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  2. Search Button in a Form
    By spideynok in forum Forms
    Replies: 14
    Last Post: 03-18-2012, 10:08 PM
  3. Replies: 9
    Last Post: 02-15-2011, 03:05 PM
  4. search button on Form
    By josejuancruz in forum Access
    Replies: 1
    Last Post: 12-23-2010, 07:21 PM
  5. Replies: 4
    Last Post: 01-11-2010, 11:41 PM

Tags for this Thread

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