Oh Board Masters...need help with Combo/List Box

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
:pray: Oh Board Masters…I need help! I have 6 list boxes on a form. I need to have the first one filtered as such… Me.Super.RowSource = ("Select DISTINCT [SUPV] from Employees") Then, I need to filter each subsequent box based on the selected item in the previous box. Can someone help?

Here is the code that I am working on:

Private Sub Form_Load()

Me.Super.RowSource = ("Select DISTINCT [SUPV] from Employees")

End Sub

Private Sub Super_AfterUpdate()

'Select a supervisor from 1st supervisor list to use as filter
'for 2nd list/combo box
Me.Super1.RowSource = "select [name] from employees where [empno] = Me.Super.ItemData(0))"
Me.Super1 = Me.Super1.ItemData(0)

'Select a supervisor from 2nd supervisor list to use as filter
'for 3rd list/combo box
Me.Super2.RowSource = "select [name] from employees where [empno] = Me.Super1.ItemData(0))"
Me.Super2 = Me.Super2.ItemData(0)

'Select a supervisor from 3rd supervisor list to use as filter
'for 4th list/combo box
Me.Super3.RowSource = "select [name] from employees where [empno] = Me.Super2.ItemData(0))"
Me.Super3 = Me.Super3.ItemData(0)

'Select a supervisor from 4th supervisor list to use as filter
'for 5th list/combo box
Me.Super4.RowSource = "select [name] from employees where [empno] = Me.Super3.ItemData(0))"
Me.Super4 = Me.Super4.ItemData(0)

'Select a supervisor from 5th supervisor list to use as filter
'for 6th list/combo box
Me.Super5.RowSource = "select [name] from employees where [empno] = Me.Super4.ItemData(0))"
Me.Super5 = Me.Super5.ItemData(0)

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,

You just need to include the Me.Super.ItemData bit outside of the " of your string. Something like this should work:-

Me.Super1.RowSource = "select [name] from employees where [empno] = " & Me.Super.ItemData(0) & ")"
 
Upvote 0
Thanks for the reply. Okay, I have tried that but when I select on the first combo box is does nothing, i.e. it does filter the records in super1 based upon the record chosen in super.
 
Upvote 0
Hi,

I just noticed that you're using ItemData(0) - that will always return the same value - the first value in the list regardless of what the user has actually selected. I think you need the Text property.

I just did a quick test and this works fine:-

Private Sub Combo0_AfterUpdate()

Me.Combo2.RowSource = "SELECT * FROM Employees where empno=" & Me.Combo0.Text

End Sub
 
Upvote 0
Hey Dk,

I made the change and now I get an error that it doesn't like the ".text" on the end. It doesn't recognize it. Error is: "Method or Data Member not found." Any further suggestions that you can offer?
 
Upvote 0
Sorry mate, I didn't read your question properly. I thought you were using comboboxes, not listboxes. Instead of Text, try Value e.g.

Me.List2.RowSource = "SELECT * FROM employees WHERE Empno=" & Me.List0.Value
 
Upvote 0

Forum statistics

Threads
1,221,535
Messages
6,160,391
Members
451,645
Latest member
hglymph

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