Hey, I'm having trouble loading a 2nd combo box based on event textchanged from a 1st Combo Box
Here is vb part.
 Private Sub tsbcmbBuilding_Click(sender As Object, e As EventArgs) Handles tsbcmbBuilding.Click
        Using con As New OleDbConnection(connectionString)
            Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '& tsbcmbBuilding.Text &'", con)
                Using dt As New DataTable
                    cmbOU.DataSource = dt
                    cmbOU.DisplayMember = "OU"
                    cmbOU.ValueMember = "ID"
                End Using
            End Using
        End Using
    End Sub

Open in new window

Here is a visual of appvb app
Here is MS Access Data I'm trying to load into combo box
ms access table
Tom PowersAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Your quotes look misplaced for starters.  Try this, and if that does not work, post back detailing exactly HOW it does not work (error message...Which one?   Incorrect results... what are the expected results vs the results you are getting?)

Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '" & tsbcmbBuilding.Text & "'", con)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
In 2007, I have written an article showing how to create a relation between 2 combos. You can read it from
Tom PowersAuthor Commented:
Eric I enjoyed your code and article I actually learned a few things but doesn't get me there
so can't get 2nd combo to load
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Éric MoreauSenior .Net ConsultantCommented:
have you tried my sample?
Did you see my post at the top of the thread?

An issue with the syntax in your original post is that the way the quotes are placed the control name is being used literally, rather than the value held in the control.

Just curious whether you tried it and what the results were.
It looks like you're trying to implement Scott McDaniel's solution here:

Again, the issue is that you've put  '& tsbcmbBuilding.Text &' inside the double quotes.  That makes your query look for the exact, literal text  '& tsbcmbBuilding.Text &', which it will find no matches for (so nothing will load in the dropdown list).

To have the query look for the value held in tsbcbmMuilding, you need to write line 3 in your original post like this, with the tsbcmbBuilding.Text outside of the double quotes, with the &'s concatenating it's value to the literal text:

Using cmd As New OleDbCommand("SELECT * FROM NAZOU WHERE Building = '" & tsbcmbBuilding.Text & "'", con)

Open in new window

Helen FeddemaCommented:
Try putting the value from tsbcmbBuilding into a String variable.  This will let you examine it in the Immediate Window to see if there are any problems with the SQL statement.
Just an advice - looking on your code and db data it seems u'r using NAZOU table much more often for select then for Update/Delete/Insert/ In this case IMHO more wise is to fill table in the beginning and refresh after Update/Delete/Insert with simple "SELECT * FROM NAZOU" query.
when you need to use filtered query as datasource, use either DataTable.Select method:
Dim source = dtOU.Select("Building='" & tsbcmbBuilding.Text & "'")

Open in new window

Dim source = (From x In dtOU.AsEnumerable() _
              Where x.Field(Of String)("Building") = tsbcmbBuilding.Text).ToList

Open in new window

Tom PowersAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.