Help find error in code - search a listbox

behedwin

Active Member
Joined
Dec 10, 2014
Messages
399
Hey

I need some help to search for errors in this code

I have used this code before to search a listbox.
But suddenly i dont get this one to work... it must be some silly error in the code, but i cant see it.
Anyone able to help me?

Code:
Private Sub txtSearch_Change()
Application.Echo False

  Dim strSource As String

  strSource = "SELECT BussElev_Table.BussElev_ID, BussElev_Table.[Elev Förnamn], BussElev_Table.[Elev Efternamn], BussElev_Table.[Elev Personnummer], Max(BussA_Table.Ansökningsdatum) AS MaxförAnsökningsdatum " & _
    "FROM BussElev_Table LEFT JOIN BussA_Table ON BussElev_Table.BussElev_ID = BussA_Table.BussElev_ID_SK " & _
    "GROUP BY BussElev_Table.BussElev_ID, BussElev_Table.[Elev Förnamn], BussElev_Table.[Elev Efternamn], BussElev_Table.[Elev Personnummer] " & _
    "Where (BussElev_Table.BussElev_ID Like '*" & Me.txtSearch.Text & "*' " _
    & "Or BussElev_Table.[Elev Förnamn] Like '*" & Me.txtSearch.Text & "*' " _
    & "Or BussElev_Table.[Elev Efternamn] Like '*" & Me.txtSearch.Text & "*' " _
    & "Or BussElev_Table.[Elev Personnummer] Like '*" & Me.txtSearch.Text & "*' " _
    & "Or BussA_Table.Ansökningsdatum Like '*" & Me.txtSearch.Text & "*') "

      Me.ListPicker.RowSource = strSource
      Me.ListPicker.Requery
      
Application.Echo True
End Sub

I dont get any error message when running it.
The listbox just emptys, so i guess the code is wrong and does not filter out what i want.
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Here are some screenshots that might help

http://prntscr.com/juw8pw
http://prntscr.com/juw8yw

still have not had any luck of figuring out what is wrong.

the code in the first post is placed in a text field.
it works in other setups jut perfectly...

this is another code where i use it, and it works just fine
Code:
Private Sub txtSearch_Change()
Application.Echo False

  Dim strSource As String

  strSource = "SELECT KeyOwnerSelect_Query.Key_ID, KeyOwnerSelect_Query.Nyckel_Kort_Nummer, KeyOwnerSelect_Query.Nyckeltyp, KeyOwnerSelect_Query.LasSystem, KeyOwnerSelect_Query.Profile_ID_SK, KeyOwnerSelect_Query.Firstname, KeyOwnerSelect_Query.Lastname, KeyOwnerSelect_Query.KeyArchived " & _
    "FROM KeyOwnerSelect_Query " & _
    "Where (KeyOwnerSelect_Query.Key_ID Like '*" & Me.txtSearch.Text & "*' " _
    & "Or Nyckel_Kort_Nummer Like '*" & Me.txtSearch.Text & "*' " _
    & "Or Nyckeltyp Like '*" & Me.txtSearch.Text & "*' " _
    & "Or LasSystem Like '*" & Me.txtSearch.Text & "*' " _
    & "Or Profile_ID_SK Like '*" & Me.txtSearch.Text & "*' " _
    & "Or Firstname Like '*" & Me.txtSearch.Text & "*' " _
    & "Or Lastname Like '*" & Me.txtSearch.Text & "*') AND KeyArchived is null "

      Me.ListPicker.RowSource = strSource
      Me.ListPicker.Requery
      
Application.Echo True
End Sub
this code works, but not the one in the first post. I can not figure out why....
 
Upvote 0
Possibly in your sql the WHERE clause must come before the GROUP BY clause.
 
Upvote 0
That fixed it.
**** so easy... ive been looking at this code all day.
An just move one row and it fixed everything :D
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top