Change a MenuBar at Runtime


D

dch3

I'm trying to build a custom MenuBar for my app. While I've got the bar up
and running, I need to know if its possible to dynamically Add or Delete
items at Run Time. I have several table setup that control the various Menu
Functions that a person has access to - based on their Windows ID. I'd like
to provide them with a Menu where the items reflected the functions that they
have access to.

Basically for one user..

FILE MENU FUNCTION EDIT
TRAILER DISPATCH
QUIT & EXIT

for another..
FILE MENU FUNCTION EDIT
PARTS INVENTORY
REPORTS
TRAILER DISPATCH
USER SETUP
QUIT & EXIT
 
Ad

Advertisements

D

dch3

Never mind, and for anyone interested here's the starter code...

Public Sub BuildMenuBar()

Dim targetMenu As Object
Dim i As Integer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim newCommand As Object

Set targetMenu = Application.CommandBars("TFC Menu").Controls("Menu
Functions")

'Remove all of the items and start fresh
For i = 1 To targetMenu.Controls.Count
targetMenu.Controls(1).Delete
Next i

Set db = DBEngine(0)(0)

Set rs = db.OpenRecordset("SELECT * FROM USystblMenufunctions ORDER BY
intSortOrder")

While Not rs.EOF
Set newCommand = targetMenu.Controls.Add
newCommand.Caption = rs("txtMenuFunctionLongName")
'newCommand.IsPriorityDropped = True
'newCommand.OnAction
'newCommand.Parameter
rs.MoveNext
Wend

rs.Close
Set rs = Nothing
Set db = Nothing

Set targetMenu = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top