How to return to same tab in main ribbon after using print preview ribbon (1 Viewer)

Ana2010

New member
Local time
Yesterday, 21:09
Joined
Dec 4, 2010
Messages
8
Windows 7 Starter. Access 2007.
I have 2 customized ribbons, one is a main cutomized ribbon and the other is a customized print preview ribbon. Each time the print preview ribbon is used, when it is closed and the main ribbon is opened again, the first tab in main ribbon is activated. I want to be activated the same tab that was active before the print preview ribbon was open. How can I do this?
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
Eight years later and I can't find a single solution for this anywhere!
I can get the tabId, I can open that tab, but cannot find a way to trigger that event.
I guess it is so simple that nobody bothered to answer...
 

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
Eight years later and I can't find a single solution for this anywhere!
I can get the tabId, I can open that tab, but cannot find a way to trigger that event.
I guess it is so simple that nobody bothered to answer...
I found lots - not that I understand all of them or can vouch that they work. Ranges from M$ saying it was done this way on purpose to "use send keys". Between this
https://access-programmers.co.uk/forums/showthread.php?t=230389
and the site it links to (which you might find a bit hard to decipher the English) you might have an answer. I dunno, but wouldn't the trigger event be the Close event of the report? I'm no ribbon expert, so I don't know if a ribbon has any such events.
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
Thanks, when you close the report the Preview ribbon is still open, so you cannot yet select a tab in the main ribbon.
I read Avelino's notes, he doesn't explain from where to fire his function
Public Function fncSetFocusTab()
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
I found a solution - there's probably a better way but this works for now. When closing the report, it opens a form that uses its ontime property to wait half a second, and then runs the fSetRibbonTab function.
Have to add this to 130+ reports, but hey, it is weekend and it is raining.
 
Last edited:

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
I don't experience that if a report ribbon is specified on the Other tab. Report closes, report ribbon closes and main ribbon comes back into view. That may be why I don't understand the original question, because I don't see the need to have a particular tab on the main ribbon activated at that point. I wasn't even aware that you could activate a tab because when I click in the tab area (not on a control) there's no evidence of 'activation'.
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
Re the need to have a particular tab opened on the main ribbon:
My main ribbon has 9 tabs. Four of these with tabs Payments, Statutory, Summaries, HRM have reports. So after running a report it is good to return to the particular report tab, so that a similar report can be selected. Rather than having to start at the Home tab.


Re where to fire the function:
When you fire the function from a report's close event, at that moment the print preview menu is still displayed, and tab selection will not work. I decided to give Access half a second to put the main ribbon back in, by opening a form with On Timer set to 500 that then fires the function and closes itself.
 
Last edited:

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
Interesting solution. Thanks for posting it.
 

isladogs

MVP / VIP
Local time
Today, 01:09
Joined
Jan 14, 2017
Messages
18,209
Alex
I've never needed to do anything like this as I provide a main menu form for users to select forms or reports (etc) rather than do this in a ribbon.

As a result, I don't have anything suitable to test your solution on.
Now that you have a working solution, would you be able to upload a cut down version to demonstrate this in use both for myself and other forum members
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
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
 
Last edited:

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
Saw the vid - I think I would open the form hidden so as to prevent the screen flashing, or maybe turn off application echo temporarily - assuming you never employ a different solution in this db. Hope you don't mind a question or 2 as I'm interested in what you're doing. Can you not call the code from the close button onAction property code?
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
Thanks Micron, I have to do something about the flashing indeed.


You mean the OnAction of the Print Preview's Close button, right? Thanks, I'm going to try that!
 

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
You mean the OnAction of the Print Preview's Close button, right? Thanks, I'm going to try that!
Yes. My guess is that that code closes the report? I'm guessing it could activate the desired tab as well. As I said, I do hope you post your solution if that works because I think you're ahead of me on the Ribbon curve and I intend to learn more than I already know about it, which isn't much.
 

AlexRigholt

Registered User.
Local time
Today, 03:09
Joined
Nov 14, 2008
Messages
36
I just had a go at it but haven't been able to capture the Print Preview Close button yet. I may have to redo the XML code that I'm using for the Print Preview button. Now I'm using this as the second record of the UsysRibbons table:


<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="true">
<tabs>
<tab id="MyReport" label="Print and View Options">

<group idMso="GroupPrintPreviewPrintAccess" />
<group idMso="GroupPageLayoutAccess" />
<group idMso="GroupZoom" />
<group idMso="GroupPrintPreviewData"/>
<group idMso="GroupPrintPreviewClosePreview" />

</tab>
</tabs>
</ribbon>
</customUI>



I'll let you know once I get it.
 

isladogs

MVP / VIP
Local time
Today, 01:09
Joined
Jan 14, 2017
Messages
18,209
Thanks for the video and code snippets but I still think it could be very useful to others to see a working example.

You shouldn't need to capture the Print Preview Close event. Just use the Report Close event
 

Micron

AWF VIP
Local time
Yesterday, 20:09
Joined
Oct 20, 2018
Messages
3,478
haven't been able to capture the Print Preview Close button yet
My guess is that you won't be able to because you're using a built in group. That would be like trying to intercept the action of any other built in button - such as Save. I suspect you would have to create your own group, add your own control, and use that.
 

Users who are viewing this thread

Top Bottom