检查 MS Access 表单中哪个选项卡被单击/处于活动状态

Vik*_* SE 4 ms-access vba

我在 MS Access 2011 中创建了一个表单,其中顶部有一个名为 TabCtl18 的选项卡控件,其中 3 个选项卡是 page1、page2、page3。page1标签下还有3个其他标签page11、page22、page33,三个标签下分别有3个报表

现在我希望当用户单击 pdf 图标时,它会检查单击了哪个选项卡并打印该报告。

我的代码:

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
Run Code Online (Sandbox Code Playgroud)

Ada*_*cha 5

根据@David 突出显示的问题,这里是检查TabPage所选名称的方法。

if tabControl1.Pages(tabControl1.Value).Caption = "TabPageName" then
    'Do Something
end if
Run Code Online (Sandbox Code Playgroud)

此外,您可以在Tab控制Click事件中使用此代码来检查哪个页面处于活动状态。