PDA

View Full Version : Find Submenu by Name



Yisman
03-24-2009, 03:30 AM
Hi everyone,
im trying to build a set of menus which will give the users access to certain reports.

the reports are grouped in categories in a table. so what i need to do is add all groups to my "reporting" menu and then add all reports to their relevant submenus.
The problem is that there seems no way to "set" GroupBar to a certain submenu by name. The GroupBar variable always evaluates to nothing. So how can I add submenu to GroupBar if I cannot "set" to it?
here is my code so far:Sub MakeMenus()
Dim AppBar As CommandBar
Set AppBar = CommandBars("MyBar")
Dim MainBar As CommandBarPopup
Set MainBar = AppBar.Controls("Reporting")
Dim SubBar As CommandBarControl
Set SubBar = MainBar.Controls("Reports")
Dim GroupBar As CommandBarControl

Dim newSub As CommandBarPopup
Dim rs As New ADODB.Recordset
rs.Open "select * from reports where fastgroup is not null", CurrentProject.Connection
Do Until rs.EOF
Set GroupBar = Nothing
'first check to seef theres such a sub already
On Error Resume Next
Set GroupBar = SubBar.Controls(rs!FastGroup) 'PROBLEM LINE
On Error GoTo 0
If GroupBar Is Nothing Then
Set GroupBar = SubBar.Controls.Add(msoControlPopup, , , , True)
GroupBar.Caption = rs!FastGroup
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End SubThank you all for taking the time to review this and answer!