Here’s a more detailed description. Sorry about the rather vague note before. I was in a hurry.
1) Create a main menu item such as "Options" or "Reports", or whatever, and make it invisible and disabled.
2) Make one sub-menu item under it, set the index to 0 to make it a control array, and disable it and make it invisible.
3) OR, set them up and when the form loads, start by disabling them and making them invisible, and then immediately run a routine to “build” the menu selection list. This is probably the better way.
4) This is a sample build routine, with mnuMyMenuItems being the name of the sub-menu control array.
Public Sub LoadMyMenu()
'This routine clears, then loads the menu.
Dim intCounter as integer
'Turn it on to work with it.
mnuMyMenuItems(0).Visible = vbTrue
'The UNLOAD removes all of the items
' except the first one from the
' list, to start building it fresh. Obviously
' if you do it once for the form, this is not
' necessary, but with it, you allow for calling
' the routine from anywhere and triggering a
' full menu rebuild.
If mnuMyMenuItems.Count > 1 Then
For intCounter = mnuMyMenuItems.Count - 1 To 1 Step -1
Unload mnuMyMenuItems(intCounter)
Next intCounter
End If
'Now load it up again.
intCounter = 0
With m_rstSourceTable
.MoveFirst
'Go through the table (or other selection
' source you have), adding the selections
' to the menu. As long as whatever you
' assign to the caption is a valid string,
' this is a good spot to do things like
' calculations and concatenations for the
' list.
Do While Not .EOF
intCounter = intCounter + 1
'This adds an item to the menu.
Load mnuMyMenuItems(intCounter)
'Set the new item properties. Yes,
' you CAN put separators or other such
' things in this way, but you will
' have to control when and where.
mnuMyMenuItems(intCounter).enabled = True
mnuMyMenuItems(intCounter).Visible = True
mnuMyMenuItems(intCounter).Caption = yourstring
.MoveNext
Loop
End With
'Turn off the first one. (I took this route
' because I was going to work with the items
' numbered 1 and onward anyway, and this was
' a simple way to just “hide” that necessary
' first one without having to change its
' properties much. If you want to use it,
' make sure you use it FIRST, before creating
' any new ones, by enabling it and changing
' the caption. Remember that if you have to make
' it invisible again later for any reason,
' do NOT UNLOAD it, as you need this one.)
mnuMyMenuItems(0).Visible = vbFalse
End Sub
5) In the menu control array’s Click event, just check
the caption of the item with that index number, and
run the code that pertains to that item. You obviously
have to make sure your spelling is good, and if you
change a caption, you have to change the hard-coded
version, but it’s well worth it. This is a great and
easy way to create customized or context-sensitive
popup menus geared to certain logged-in users or to
the previous steps the user has followed.