depending listboxes

  • Thread starter Thread starter Jean-Paul
  • Start date Start date
J

Jean-Paul

Hi,
I have a form with 2 listboxes.
the second one should be based upon the first one, so, if I go to the
next value in the first listbox, the second one should change too.

I wrote this code:

Private Sub Keuzelijst0_Click()
Dim sql As String
sql = "SELECT Sub_doel.Hoofddoel, Sub_doel.Sub_doel,
Sub_doel.Omschrijving FROM Sub_doel WHERE Sub_doel.Hoofddoel= " &
Forms!Doelstellingen!Keuzelijst0 & " ORDER BY Sub_doel.Sub_doel;"

Me!Keuzelijst2.RowSource = sql
Me!Keuzelijst2.Requery
End Sub

But, when nothing changes when I change Keuzelijst0

(finally, more listboxes chould change when the first one is changed)

What am I doing wrong?

Thanks
 
troubleshoot: run the sql as a query....and after you select in list1 ...run
this query and see if its results are correct
 
I did what you suggested:


Private Sub Keuzelijst0_AfterUpdate()
Dim sql As String
sql = "SELECT Sub_doel.Hoofddoel, Sub_doel.Sub_doel,
Sub_doel.Omschrijving FROM Sub_doel WHERE Sub_doel.Hoofddoel= " &
Forms!Doelstellingen!Keuzelijst0 & " ORDER BY Sub_doel.Sub_doel;"
Me!Keuzelijst2.RowSource = sql
Me!Keuzelijst2.Requery
End Sub

Same result... no records displayed in the second listbox
 
When you say that the SQL is correct and shows the correct records, how did
you determine that?

Your code is

Dim sql As String
sql = "SELECT Sub_doel.Hoofddoel, Sub_doel.Sub_doel,
Sub_doel.Omschrijving FROM Sub_doel WHERE Sub_doel.Hoofddoel= " &
Forms!Doelstellingen!Keuzelijst0 & " ORDER BY Sub_doel.Sub_doel;"
Me!Keuzelijst2.RowSource = sql
Me!Keuzelijst2.Requery

What happens if you change that to

Dim sql As String

sql = "SELECT Sub_doel.Hoofddoel, Sub_doel.Sub_doel,
Sub_doel.Omschrijving FROM Sub_doel WHERE Sub_doel.Hoofddoel= " &
Forms!Doelstellingen!Keuzelijst0 & " ORDER BY Sub_doel.Sub_doel;"

Debug.Print sql

Me!Keuzelijst2.RowSource = sql
Me!Keuzelijst2.Requery


After the code runs, go to the Immediate Window (Ctrl-G) and check the SQL
that was generated. Does it run correctly?
 
perfect...
I copy paste it as a query... correct records are displayed
In the second listbox.... nothing
JP
 
Guys... problem solved...

I accidently deleted the type of recordsource...

Thanks for your kind help
JP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Empty listbox 1
Variable expected 3
Listbox not populating every time 1
List Box won't refresh 2
ListBox.Requery 1
changing query 1
SetFocus OnOpen to two listboxes? 5
Changing Column Heads in Listbox 5

Back
Top