Results 1 to 5 of 5
  1. #1
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61

    Search Code does not work, anyone able to find the problem?

    Hi

    I need some help find a error in my code.
    I have been banging my head against this for some time now.

    I have a textbox that is called txtSearch
    It is supposed to search in a listbox. So when the user typse in the textbox, the result filters down in the listbox. This code have worked many times but i can not figure out why this one is not working now.
    Listbox is called: ListPicker

    My SQL for the listbox is this when form is being loaded.
    Code:
    SELECT SelecBuss_Query.ElevFirstname, SelecBuss_Query.ElevLastname, SelecBuss_Query.Arskurs, SelecBuss_Query.BussElev_ID, SelecBuss_Query.Expression1
    FROM SelecBuss_Query
    GROUP BY SelecBuss_Query.ElevFirstname, SelecBuss_Query.ElevLastname, SelecBuss_Query.Arskurs, SelecBuss_Query.BussElev_ID, SelecBuss_Query.Expression1
    ORDER BY SelecBuss_Query.Arskurs;
    As you can see it is based on a Query
    The Query looks like this:


    Code:
    SELECT BussElev_Table.ElevFirstname, BussElev_Table.ElevLastname, BussElev_Table.Arskurs, BussElev_Table.BussElev_ID, Max([Ansokningsdate] & " " & [kommentar]) AS Expression1
    FROM BussElev_Table LEFT JOIN BussA_Table ON BussElev_Table.BussElev_ID = BussA_Table.BussElev_ID_SK
    GROUP BY BussElev_Table.ElevFirstname, BussElev_Table.ElevLastname, BussElev_Table.Arskurs, BussElev_Table.BussElev_ID
    ORDER BY BussElev_Table.Arskurs;

    Then finaly i have the VBA code that runs the search.
    It looks like this
    Code:
    Private Sub txtSearch_Change()
    Application.Echo False
    
      Dim strSource As String
      
      
      
       strSource = "SELECT SelecBuss_Query.ElevFirstname, SelecBuss_Query.ElevLastname, SelecBuss_Query.Arskurs, SelecBuss_Query.BussElev_ID, SelecBuss_Query.Expression1 " & _
        "FROM SelecBuss_Query " & _
        "Where (SelecBuss_Query.ElevFirstname Like '*" & Me.txtSearch.Text & "*' " _
        & "Or SelecBuss_Query.ElevLastname Like '*" & Me.txtSearch.Text & "*' " _
        & "Or SelecBuss_Query.Arskurs Like '*" & Me.txtSearch.Text & "*' " _
        & "Or SelecBuss_Query.BussElev_ID Like '*" & Me.txtSearch.Text & "*' " _
        & "Or SelecBuss_Query.Expression1 Like '*" & Me.txtSearch.Text & "*') " _
        & "ORDER BY SelecBuss_Query.Arskurs; " _
        & "GROUP BY SelecBuss_Query.ElevFirstname, SelecBuss_Query.ElevLastname, SelecBuss_Query.Arskurs, SelecBuss_Query.BussElev_ID, SelecBuss_Query.Expression1 "
    
          Me.ListPicker.RowSource = strSource
          Me.ListPicker.Requery
    
    Me!ListPicker = ""
    Application.Echo True
    End Sub

    Anyone able to help me solve this.

    I have other codes exaclty like this that do work.
    But this one just cleares my listbox and it is empty.
    I can not understand why.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Paste the code into Sql view of a query, change to design view and see if it works.
    If not remove all where filters and repeat.
    Then restore the filters one at a time checking it still works,
    When done paste the sql back into the vbe

    You may all find this utility useful from my website http://www.mendipdatasystems.co.uk/s...ain/4594398120
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    kevinjoseph is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2018
    Posts
    3
    I have different codes exaclty like this that do work. In any case, this one just cleares my listbox and it is unfilled. I can not comprehend why.

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    No ... but you can systematically identify the issue like I suggested.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    ORDER BY clause should follow GROUP BY clause.

    But why have GROUP BY since there are no aggregate functions? Try SELECT DISTINCT instead.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-18-2015, 09:47 PM
  2. Replies: 8
    Last Post: 07-03-2015, 05:03 PM
  3. Replies: 3
    Last Post: 01-04-2015, 06:09 PM
  4. Find Button won't work if Data Entry = Yes
    By Heatshiver in forum Forms
    Replies: 3
    Last Post: 12-23-2011, 01:49 PM
  5. !!!!Urgent!!!! Search code doesn't work!
    By Laetilae in forum Programming
    Replies: 4
    Last Post: 12-13-2010, 10:34 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