Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check which tab is clicked / Active in a MS Access form

Tags:

vba

ms-access

I have created a form in MS Access 2011 in which there are a tab control on top named TabCtl18 in which 3 tabs are page1, page2, page3. Under the page1 tab there are another 3 other tabs page11, page22, page33, under three tabs there are 3 reports respectively

Now I want that when a user clicks on pdf icon it check which tab has clicked and print that report.

My Code :

Private Sub cmdPrintReportPDF_Click()

    If TabCtl18.TabIndex = 0 Then

        If tab_graph.TabIndex = 0 Then

            DoCmd.OpenReport "Graph_report", acViewNormal
            DoCmd.OutputTo acOutputReport, "Graph_report"
            DoCmd.Close acReport, "Graph_report"

        End If
    Else
        If tab_graph.TabIndex = 2 Then

            DoCmd.OpenReport "Graph_Report_FieldShifts", acViewNormal
            DoCmd.OutputTo acOutputReport, "Graph_Report_FieldShifts"
            DoCmd.Close acReport, "Graph_Report_FieldShifts"
        End If

    End If
End Sub
like image 413
Vikram SE Avatar asked Feb 25 '23 01:02

Vikram SE


1 Answers

Based on issue highlighted by @David, here is the way to check name of the TabPage selected.

if tabControl1.Pages(tabControl1.Value).Caption = "TabPageName" then
    'Do Something
end if

Moreover, You can use this code in Tab Control Click Event to check which Page is active.

like image 167
Adarsh Madrecha Avatar answered Mar 05 '23 22:03

Adarsh Madrecha