Hi, below the code that I use. Here's a demo clip if you want to see it in action:
https://www.dropbox.com/s/rhoqgmtcxmnmxle/DemoReturnToTab.mp4?dl=0
' in USysRibbons add keytips to each tab, for example
<tab id="tabPayments" label="Payments" keytip = "H3">
<tab id="tabStatutory" label="Statutory" keytip = "H4">
<tab id="tabSummaries" label="Summaries" keytip = "H5">
etc.
' declare public variables
Public gstrTabTip As String
Public gstrTabID As String
' in the callback module, identify the Tab that you need to return to after exiting from the print preview ribbon
Public Sub OnActionButton(control As IRibbonControl)
If Left(control.id, 8) = "Payments" Then
gstrTabTip = "%H3%"
gstrTabID = "TabPayments"
ElseIf Left(control.id, 9) = "Statutory" Then
gstrTabTip = "%H4%"
gstrTabID = "tabStatutory"
ElseIf Left(control.id, 9) = "Summaries" Then
gstrTabTip = "%H5%"
gstrTabID = "tabSummaries"
ElseIf Left(control.id, 3) = "HRM" Then
gstrTabTip = "%H7%"
gstrTabID = "tabHRM"
Else
gstrTabTip = ""
gstrTabID = ""
End If
Select Case control.id
etc.
' VBA in the form frmSelectTab. Set itsTimer Interval to 500. Call it from the close event of the report.
Private Sub Form_Open(Cancel As Integer)
DoCmd.Minimize
End Sub
Private Sub Form_Timer()
If Len(gstrTabID) > 0 Then
SetRibbonTab gstrTabTip, gstrTabID
gstrTabTip = ""
gstrTabID = ""
End If
DoCmd.Close acForm, "frmSelectTab"
End Sub
Public Function SetRibbonTab(strTabTip As String, strTabID As String)
' source:
http://www.ribbons-access.com/ms-access/ribbon-support-faq.asp#inicio
Dim selRib As Object
Select Case CCur(Application.Version)
Case Is < 13
Set selRib = CreateObject("WScript.shell")
selRib.SendKeys strTabTip
Set selRib = Nothing
Case Else
gobjRibbon.ActivateTab strTabID
End Select
' Usage: SetRibbonTab "%H1%", "tabFile" Note specifically the use of '%' delimiting the screentip value
End Function