469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How to refresh multiple listboxes in a form based on the 1st listbox?

I have a form that has 4 list boxes and I need to refresh them on the fly when user select something in the first listbox. I need to make sure that all the other three boxes change it's value based on the 1st box selection without clicking any submit button.
Jul 23 '10 #1

✓ answered by slenish

I have had to do something like this myself. I found this link helpful. They use combo boxes but you could make some adjustments to get it to work with list boxes.

Hope this helps

http://www.databasedev.co.uk/filter_combo_boxes.html

11 7163
slenish
283 100+
I have had to do something like this myself. I found this link helpful. They use combo boxes but you could make some adjustments to get it to work with list boxes.

Hope this helps

http://www.databasedev.co.uk/filter_combo_boxes.html
Jul 23 '10 #2
NeoPa
32,173 Expert Mod 16PB
Put some code in the AfterUpdate event of the first ListBox that calls a .Requery() for each of the other ListBoxes. Something like :
Expand|Select|Wrap|Line Numbers
  1. Private ListBox1_AfterUpdate()
  2.     Call Me.ListBox2.Requery()
  3.     Call Me.ListBox3.Requery()
  4.     Call Me.ListBox4.Requery()
  5. End Sub
Jul 24 '10 #3
@NeoPa
All,

Listbox2 needs to be refreshed based on the listbox1's selection. If I do the above it doesn't work. Any suggestions?
Jul 26 '10 #4
NeoPa
32,173 Expert Mod 16PB
dpatel1682: Listbox2 needs to be refreshed based on the listbox1's selection. If I do the above it doesn't work. Any suggestions?
Only that you may have used it incorrectly. I see no other reason why it would fail to work.

I don't feel inclined to waste any more effort here though, if all the information you can feed back is that "it doesn't work".

If/when you post a response with some information in to work with I will look again.
Jul 26 '10 #5
@NeoPa
Sorry for not providing enough info. Actually, it worked with slenish's suggested site with few modification of the code. Thanks again for your help and time
Jul 26 '10 #6
NeoPa
32,173 Expert Mod 16PB
I understand it's not always easy to post everything required. It's always hard to work without it though.

I'm pleased Slenish's post helped you anyway, and thanks for posting you got a result.
Jul 26 '10 #7
govnah
9
Hi there, I am trying to do something similar to what you just achieved. I was hoping you could post the code you used to solve the problem.

Many Thanks
Aug 5 '10 #8
NeoPa
32,173 Expert Mod 16PB
Govnah,

We're very happy if you find an answer to your question in an existing thread. If you find that it is not quite right, then this thread is unlikely to be a close enough match, and you should post your question, optionally with a link to this or another thread, in its own thread.

I suspect in this case you could find what you're after by following the link. As I say, if not, then post your own thread.
Aug 5 '10 #9
Govnah,

What i did was I wrote a code in the after update event which sets a record set for the next list box. If you have multiple list boxes which needs to get refreshed based on the first input then you have to write code for the other boxes based on its value. Here's the sample

Expand|Select|Wrap|Line Numbers
  1. Private Sub List5_AfterUpdate()
  2.  
  3. Dim sAccountName As String
  4. Dim sSubAccountType As String
  5.  
  6.     sSubAccountType = "SELECT distinct Main_Account_Type, Sub_Account_Type " & _
  7.                      "FROM tbl_Account " & _
  8.                      "where Main_Account_Type = " & "'" & Me.List5.Column(1) & "'" & _
  9.                      "and sub_account_type <> ''"
  10.  
  11.     Me.List7.RowSource = sSubAccountType
  12.     Me.List7.RowSourceType = "TABLE/QUERY"
  13.     Me.List7.Requery
  14.  
  15. sAccountName = "SELECT Main_Account_Type, Account_Name " & _
  16.                      "FROM tbl_Account " & _
  17.                      "Group by Main_Account_type, Account_Name " & _
  18.                      "having Main_Account_Type = " & "'" & Me.List5.Column(1) & "'" & _
  19.                      "and Account_Name <> ''"
  20.  
  21.     Me.List9.RowSource = sAccountName
  22.     Me.List9.RowSourceType = "TABLE/QUERY"
  23.     Me.List9.Requery
  24.  
  25. End Sub
Please let me know if you have any quesitons.
Aug 5 '10 #10
govnah
9
dpatel1682,

Thank you for taking the time out to post the sample.

I noticed you don't have a loop in your code, which will check every column (record) in the listbox. That's what i'm struggling with.

how come you're your using this? "Me.List5.Column(1)"

Expand|Select|Wrap|Line Numbers
  1. "having Main_Account_Type = " & "'" & Me.List5.Column(1) & "'"
I think thats a whole thread on its own. I'll take NeoPa's advice and open a new thread.

Thank you dpatel1682, NeoPa
Aug 6 '10 #11
govnah
9
Thank You so much guys.

I went back and really had a go at figuring out how the whole listbox thing works. Then i came back to the code you provided 'dpatel1682' and it really did the trick.


Thanks again
Aug 15 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by ___Newbie___ | last post: by
6 posts views Thread by Frank Walsh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.