Is there a way to hide the Navigation Pane, and Menu Bar on launch using MSAccess VB? Point is to remove "distractions" from users using MSAccess solution.
Fig A: Hiding the Navigation Pane and Menu Bar
Option 1
One easy way is to rename the *.accdb to *.accdr.
Then it will be opened in runtime mode without ribbon bar and navigation pane.
Option 2
Call the database by full command line of Microsoft Access and the database and the command line parameter /runtime, then it also will be opened in runtime mode.
Example:
"c:\Program Files (x86)\Microsoft Office\Office15\msaccess.exe" "c:\data\yourDatabase.accdb" /runtime
(the path of Microsoft Access varies regarding your installation of Access (msi or c2r, x86 or x64, version of access, custom installation folder...)
Option 3
You can hide them by code:
Navigation Pane: https://stackoverflow.com/a/47519552/7658533
Ribbon: https://stackoverflow.com/a/35582657/7658533
Personally I use below codes to hide navigation pane & ribbon to my databases. You can also try-
Private Sub Form_Load()
On Error GoTo HarunErrHandler
'******************* Hide Ribbon and Navigation Pane ***************************
DoCmd.ShowToolbar "Ribbon", acToolbarNo
Call DoCmd.NavigateTo("acNavigationCategoryObjectType")
Call DoCmd.RunCommand(acCmdWindowHide)
'*******************************************************************************
Exit Sub
HarunErrHandler:
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description, vbInformation, "Error"
End Sub
If you need to show them again then use below codes.
'******************* Show Ribbon and Navigation Pane ***************************
DoCmd.ShowToolbar "Ribbon", acToolbarYes
Call DoCmd.SelectObject(acTable, , True)
'*******************************************************************************
Related
I am working with MS Access and I am currently trying out the navigation sub-forms. However I am finding it difficult to understand how to simply change the recordsource of a sub form. One of the tabs within my "NavigationSubform" is called "nbCustomerList", which has the target navigation name "CustomerList". Within the CustomerList form, there is a button which when clicked opens a popup which allows you to filter the query on CustomerList. How do I achieve a change to recordsource from an event like this?
Private Sub btnSearch_Click()
On Error GoTo HandleError
If CurrentProject.AllForms("MainMenu").IsLoaded Then
[Forms]![CustomerList].RecordSource = CustomerListFilter()
[Forms]![MainMenu]![NavigationSubform].Requery
End If
''ErrorHandling'''''''''''''''''''''''''''''''''''''''''''''''''''''''
HandleExit:
Exit Sub
HandleError:
MsgBox (Err.Number & ": " & Err.Description)
Resume HandleExit
End Sub
The following test worked for me:
Forms![Navigation Form].NavigationSubform.Form.RecordSource = "SELECT * FROM Rates WHERE ID=2"
Assuming your form design has the default names of [Navigation Form] and NavigationSubform assigned by Access, in your db try:
[Forms]![Navigation Form].NavigationSubform.Form.RecordSource = CustomerListFilter()
Requery command was not necessary.
I don't use Navigation Form design. Keep in mind that no matter how many tabs are set up, only one subform is available at any time. Nature of Navigation Form is that it loads and unloads subforms as called by click on tabs.
I have written several custom UI Ribbon menus for both Excel and Word. I have working custom context (right click) menus with my Excel apps, but cannot seem to get them to work in Word. I used the same coding as with my working menus in Excel and wrote the XML using the "Custom UI Editor for Microsoft Office" so there should be no issue.
I will post my code. The real question is will this type of custom menu work in Word at all?
The XML in the ribbon code is (showing the last lines only):
</tabs>
</ribbon>
<contextMenus>
<contextMenu idMso="ContextMenuCell">
<dynamicMenu id="mnuMain" label= "BidSmart Contract" imageMso="DocumentTemplate" getContent="GetContent" insertBeforeMso="Cut"/>
</contextMenu>
</contextMenus>
The getContent sub, "GetContent" looks like this:
Sub GetContent(control As IRibbonControl, ByRef returnedVal)
Dim xml As String
xml = "<menu xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">" & _
"<button id=""mnuCtxtEmail"" label=""Send and Email"" imageMso=""TableSharePointListsRefreshList"" screentip=""Send an Email to the Client, Designer or Contractor..."" onAction=""mnuEmail""/>" & _
"<button id=""mnuCtxtEnvelope"" label=""Print an Envelope"" imageMso=""WhatIfAnalysisMenu"" screentip=""Create an Envelope addressed to the Client, Designer or Contractor..."" onAction=""mnuEnvelope""/>" & _
"</menu>"
returnedVal = xml
End Sub
If you are using the same ribbon XML you won't get your XL context menu to work in WD. You need to find the correct idMso for the context menu in WD that you want to add your menu to. You can get the control ids here: Office 2016 control ids
I have a vba sub ("sub") in excel 2013, which opens another workbook, reads some data out of it, return this data and close the newopened workbook. It is possible to run this sub via keyboard shortcut and a entry in the context menu.
This call (the "UTILS.sub" this is) works perfectly fine:
' Add the sub-call to a new context menu entry
Call UTILS.addContextMenuEntry("Caption", 2556, "UTILS.sub")
But this call doesn't:
' Add the sub-call to a new keyboard shortcut
App.OnKey "+^{M}", "UTILS.sub"
If i call sub with the keyboard shortcut it breaks without an error. I've managed to work out the specific code line, at which it breakes via debugging:
'[...]
Application.ScreenUpdating = False
' Open the external Workbook
Set wbHandle = Workbooks.Open("wb.xls", ReadOnly:=True)
MsgBox "Debug"
'[...]
wb.xls opens (and displays), but the MsgBox "Debug" does not. Nothing after the "Open"-line does run and no breakpoint after this line will be hit. Another strange thing: If i debug a call of sub with a breakpoint before that line, it all works perfectly.
How to get the sub to run correctly, not regarding wether it was called by a context menu entry or keyboard shortcut?
I'm not exactly sure what the cause of this behavior is, but I suspect that macros called via keyboard shortcuts or context menus are actually passed through Application.Run or something else that can reset the execution state internally.
The simple work-around seems to be to pass execution through a "wrapper" sub:
Public Sub bar()
foo
End Sub
Public Sub foo()
Dim bar As Workbook
Set bar = Workbooks.Open("C:\Book1.xls", ReadOnly:=True)
MsgBox "foo"
End Sub
Launching foo by a keyboard shortcut will not display the message box, but calling bar will.
I've found the answer to my problem by myself: stackoverflow.com/questions/17409524/
Apparently, excel can't handle the "Workbooks.Open()"-method if the sub is called through a keyboard shortcut, which includes the [SHIFT]-key. Solution: Use "Workbooks.Add()" instead.
I want to make appear a new element on the shortcut menu, known also as right-click menu. I want this element to execute a macro that I made. I check on the web but I could find a solution that really work. I put here which one I tried:
Public Sub customizeRightClick()
Dim pic As IPictureDisp
Set pic = LoadPicture("C:\path\pic.jpg")
For Each oCmdBar In Application.CommandBars
If oCmdBar.Type = msoBarTypePopup Then
If oCmdBar.Name = "Shapes" Then
Set cmdButton = oCmdBar.Controls.Add(Type:=msoControlButton)
With cmdButton
.Caption = "Edit Element"
.Tag = "Edit"
.Picture = pic 'Object of type IPictureDisp
.OnAction = "editMag"
End With
End If
End If
Next
End Sub
I check in the Watches and it add the control but when I use right-click on a shape the options doesn't appear. Maybe I am not putting where it have to be but I cannot find anywhere an explanation about where is the correct place to set the new element.
David's correct re 2007, but it seems they've added the ability to customize context menus back in PPT 2010:
http://social.msdn.microsoft.com/forums/office/en-US/c1eb22ba-6ca8-4c21-8100-62185355aa53/customize-rightclick-context-menu-in-powerpoint-2010
OK I have confirmed that there is:
Limited support for shortcut menu customizations in PPT 2007+
specifically. ....You cannot add any item to the shapes shortcut menu
(unless it is an activex control) in PPT 2007+.
http://answers.microsoft.com/en-us/office/forum/office_2007-customize/customizing-right-click-menu/76aff9b3-9253-40cf-bd21-e1f832144ad8
You may be able to do this with Ribbon/XML interface, but again it may be subject to the annoying limitation that they put on certain context menus. It might simply not be possible to do what you want to do in this version of PowerPoint.
http://msdn.microsoft.com/en-us/library/gg469862.aspx#odc_xl_ta_CustomExcelContextMenus_AddDynamicMenu
I have a simple COM add-in for office that I am developing (for access specifically).
I have added a custom commandbarbutton item to the context menu that pops up when you right click on an object in the navigation pane.
This works fine. The debug code I added runs (currently just a msgbox command). The one thing I cannot figure out how to do though is get an object for the object bound to the context menu.
I would like this to happen; I right click on a module in the navigation pane, select my new menu option, and then a message box appears with the name of the module that is currently highlighted. How would I go about this?
This is how I am currently handling the event:
Public Sub myEventHandler(ByVal ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles contextMenu_navPaneObject.Click, contextMenu_navPaneList.Click
MsgBox(Microsoft.VisualBasic.Information.TypeName(ctrl) & vbCrLf & _
Microsoft.VisualBasic.Information.TypeName(ctrl.Parent) & vbCrLf & _
Microsoft.VisualBasic.Information.TypeName(ctrl.Parent.Parent))
End Sub
contextMenu_navPaneObject and contextMenu_navPaneList are private objects declared using "withevents" and having an object type of commandbarbutton.
Is this the correct way to do what I want, or is there an alternative method I should be using?
Turns out to do what I wanted, I needed to run the following method:
Access.Application.CurrentObjectName()
This returned the name of the item I currently had highlighted.
I hope this helps others!