UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Select Ribbon Tab    
Select Ribbon Tab

Setting Focus to a Specific Ribbon Tab (A2007 on)

You can set focus onto a ribbon tab using VBA code in all versions of Access from A2007 onward;
for A2010 and later there is a built in function that allows you to change tabs (objRibbon.Activate "TabID"),
Access 2007 requires using the SendKeys Command; however the WSscript.shell method should prevent the known sendkeys problems

This wiki function can be added to a code module, and can be used with A2007 as well as later versions.

1. Changes to the ribbon XML
Add a screen tip for each Ribbon Tab, the screen tip must be "H1", "H2", "H3" etc.
The first character must be 'H' and subsequent characters numbers e.g.

CODE
<  tab id="tabFile" label="File" keytip="H1" >

2. Code function
Add this code function to a module

CODE

Public Function fSetRibTab(strTabTip As String, strTabID As String)

Dim selRib  As Object

Select Case CCur(Application.Version)
Case Is < 12
   'Exit if pre-ribbon version!
   MsgBox "Ribbbon functions are not available in this version of Access.", vbExclamation, "Set Ribbon Tab"
   Exit Function
   
Case Is < 13
   Set selRib = CreateObject("WScript.shell")
   selRib.SendKeys strTabTip
   Set selRib = Nothing

Case Else
   objRibbon.ActivateTab strTabID

End Select

End Function

NOTE: Replace 'objRibbon' in the above code with your custom ribbon pointer for the ribbon.

3. To set focus to a specific tab
Call the function as: (e.g.) fSetRibTab "%H1%", "tabFile"
Note specifically the use of '%' delimiting the screentip value


Acknowledgement:
The above code is based on Avelino Sampio's suggested solution which inspired me to create the function.

Edit Discussion
Custom Search


Thank you for your support!
This page has been accessed 4,101 times.  This page was last modified 12:04, 24 November 2014 by Pere_de_chipstick.   Disclaimers