PDA

View Full Version : Listboxes .Visible = False (Hide/Unhide Menus)



Len Piwowar
02-09-2006, 08:20 PM
Just started playing with Access.VBA and trying to create a menu system. I setup tables where each one is used to fill a listbox to create a simple menu. When the 1st listbox is selected an (event procedure) click runs a sub procedure which passes the Bound value to a varable and becomes the next menus name. I then make the next Listbox menu visible. And based the that selection the next menu becomes visible.

Question:
If Menus1, Menus2, Menus3 and Menus4 are Visible and Menus2 is clicked I would like Menus3 and Menus4 to have visible = False using something like a for next statement. I tried Using a procedure like:

For X = 2 to MenusOpened
MenuNam = "Menus" & X
MenuName.visible = False
Next

But the reference to the menus name will not work??
I have attached the current Elect Menus DB and code but haven't been able to have the menus to the right of the current one close when a menu on the left is selected.

Thanks in advancehttp://vbaexpress.com/forum/images/smilies/102.gifhttp://vbaexpress.com/forum/images/smilies/102.gif

XLGibbs
02-09-2006, 08:45 PM
At quick glance, the method you describe would not work as written and would require that the list boxes were actually created as an array and the syntax would be slightly different. Incidentally, the names of your other menus are not as you state...They have MainMenu, HV1 and some other strings of numbers as they progress.

This idea can be accomplished by having them all with the same name so that they appear in the list indexed such as ListBox(1), ListBox(2) etc...

That way you could have done..

i = Me.Index which would return the index number of the active list box (on click presumably, you would call the same procedure from each boxes click event based on your intent i think)

then it would be
ListBox(i-1).Visible = False
ListBox(i).Visible = True

but, i think it easier to simply have each list box click event point to the next one, since yours are already named.

Sub MainMenu_Click
Me.Visible = False
HV1.Visible = True
HV1.SetFocus
End Sub


An easy way to create a listbox as an array of indexed listboxes is to create one, the make copies of it. The copy will have the same name and each copy will incrementally have an index number..so if you were to copy MainMenu it would be copied incrementally with each successive copy being 1 higher ...

Hope that helps...