Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restore selection on listbox dependant on another listbox. 1

Status
Not open for further replies.

CoolFactor

Technical User
Dec 14, 2006
110
US
Hello,

I have couple list boxes on a form that depend on each other . In list box 1 I have the following VBA code in the Before Update Event:

Private Sub ListBox1_BeforeUpdate(Cancel As Integer)
Me!ListBox2.Requery
End Sub

When I select an item in list box 1 then list box 2 shows the relevant information for that item selected in list box 1. I know how to clear the selections when any item is selected in list box 1 but what I really need is how to undo the Before Update Event using a command button so that list box 2 shows nothing because I haven't selected anything from list box 1.

Thank you,

Anthony
 
How are ya CoolFactor . . .

I believe your talking the initial state of affairs when you first open the form. If this is true you can simply [blue]requery the list boxes[/blue]. However, requery doesn't work with listboxes so use the following instead:
Code:
[blue]   Me![purple][B][I]ListboxName1[/I][/B][/purple].RowSource = Me![purple][B][I]ListboxName1[/I][/B][/purple].RowSource
   Me![purple][B][I]ListboxName2[/I][/B][/purple].RowSource = Me![purple][B][I]ListboxName2[/I][/B][/purple].RowSource[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I put this piece of code in the command button on click but nothing happens.
 
CoolFactor . . .

Make a selection from listbox1. Check the values in the list of listbox2 then hit the button and check the list in listbox2 again.

If the listboxes are in their initial state (as in opening the form), no changes will occur . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
CoolFactor . . .

Assuming you replaced the listbox names in purple, post the [blue]SQL[/blue] of each rowsource.

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
CoolFactor . . .

and this:
Code:
[blue]   Me![purple][B][I]ListboxName1[/I][/B][/purple] = Null
   Me![purple][B][I]ListboxName2[/I][/B][/purple] = Null
   Me![purple][B][I]ListboxName2[/I][/B][/purple].RowSource = Me![purple][B][I]ListboxName2[/I][/B][/purple].RowSource[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
CoolFactor . . .

Great! ... I keep reading and reading the thread trying to find what I missed, when my library revealed a powerful fact:
TheAceMan1 said:
[blue]Selections are not removed when you requery a listbox! [purple]Always remove selections before you do![/purple][/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top