G
Guest
I have 2 routines that almost produce the results I want.
1) EnableDefaultMenu () ---just resets everything
2) InvokeUserMenu () ---almost works - but probably serendipitously
I have a startup routine that checks users and sets their menu, because the
"ChangeProperty" routine I tried will only work after the NEXT time the
database is open. The above routines happen immediately.
The InvokeUserMenu effectively removes the other menus I dont' want them to
see, so I probably don't need the inner loop. (It doesn't even touch it)
It boils down to - It sure would be nice if whenever a report is open the
only button a user sees is the "CLOSE" button - the one that closes the
report (not exit, or any other button or menu)
If anyone has CommandBar down to a science, please help me figure out how to
adjust this code to get the results I want?
'Code provided below
'====================================================
Public Sub EnableDefaultMenu()
On Error Resume Next
Dim obar As CommandBar
For Each obar In Application.CommandBars
obar.Reset
Next
End Sub
Public Sub InvokeUserMenu()
Dim cbarMenu As CommandBar
Dim cbarControl As CommandBarControl
Dim strBar As String
Dim strList As String
On Error Resume Next
For Each cbarMenu In Application.CommandBars
For Each cbarControl In cbarMenu.Controls 'command bars
If cbarControl.Caption = "&File" Or cbarControl.Caption = "&Edit"
Or cbarControl.Caption = "&Window" Then 'parent menus
'MsgBox "Parent Menu: " & cbarControl.Caption
MsgBox "Will Keep this menu: " & cbarControl.Caption
'====================== 'menu items
If cbarControl.Type = msoBarTypeMenuBar Then
'If cbarControl.Enabled = True Then
' MsgBox "menu item: " & cbarControl.Caption
If cbarControl.Caption = "&Close" Or _
cbarControl.Caption = "&Print" Or _
cbarControl.Caption = "&Find..." Or _
cbarControl.Caption = "R&eplace..." Or _
cbarControl.Caption = "Ti&le Horizontally" Or _
cbarControl.Caption = "&Tile Vertically" Or _
cbarControl.Caption = "&Cascade" Or _
cbarControl.Caption = "Microsoft Access &Help"
Then
'any item from the above list should be enabled
MsgBox "Will keep this menu item: " &
cbarControl.Caption
Else ' not a chosen menu item
cbarControl.Visible = False
End If
'End If 'item was enabled
End If 'checking if it is a menuitem
'=====================
Else 'if not one of the chosen menus... disable it
cbarControl.Visible = False
End If
Next
Next
Set cbarMenu = Nothing
End Sub
1) EnableDefaultMenu () ---just resets everything
2) InvokeUserMenu () ---almost works - but probably serendipitously
I have a startup routine that checks users and sets their menu, because the
"ChangeProperty" routine I tried will only work after the NEXT time the
database is open. The above routines happen immediately.
The InvokeUserMenu effectively removes the other menus I dont' want them to
see, so I probably don't need the inner loop. (It doesn't even touch it)
It boils down to - It sure would be nice if whenever a report is open the
only button a user sees is the "CLOSE" button - the one that closes the
report (not exit, or any other button or menu)
If anyone has CommandBar down to a science, please help me figure out how to
adjust this code to get the results I want?
'Code provided below
'====================================================
Public Sub EnableDefaultMenu()
On Error Resume Next
Dim obar As CommandBar
For Each obar In Application.CommandBars
obar.Reset
Next
End Sub
Public Sub InvokeUserMenu()
Dim cbarMenu As CommandBar
Dim cbarControl As CommandBarControl
Dim strBar As String
Dim strList As String
On Error Resume Next
For Each cbarMenu In Application.CommandBars
For Each cbarControl In cbarMenu.Controls 'command bars
If cbarControl.Caption = "&File" Or cbarControl.Caption = "&Edit"
Or cbarControl.Caption = "&Window" Then 'parent menus
'MsgBox "Parent Menu: " & cbarControl.Caption
MsgBox "Will Keep this menu: " & cbarControl.Caption
'====================== 'menu items
If cbarControl.Type = msoBarTypeMenuBar Then
'If cbarControl.Enabled = True Then
' MsgBox "menu item: " & cbarControl.Caption
If cbarControl.Caption = "&Close" Or _
cbarControl.Caption = "&Print" Or _
cbarControl.Caption = "&Find..." Or _
cbarControl.Caption = "R&eplace..." Or _
cbarControl.Caption = "Ti&le Horizontally" Or _
cbarControl.Caption = "&Tile Vertically" Or _
cbarControl.Caption = "&Cascade" Or _
cbarControl.Caption = "Microsoft Access &Help"
Then
'any item from the above list should be enabled
MsgBox "Will keep this menu item: " &
cbarControl.Caption
Else ' not a chosen menu item
cbarControl.Visible = False
End If
'End If 'item was enabled
End If 'checking if it is a menuitem
'=====================
Else 'if not one of the chosen menus... disable it
cbarControl.Visible = False
End If
Next
Next
Set cbarMenu = Nothing
End Sub