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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6142927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:20:13  来源:igfitidea点击:

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

vbams-accessaccess-vba

提问by Vikram SE

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

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

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

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

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

回答by Adarsh Madrecha

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

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

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

Moreover, You can use this code in TabControl ClickEvent to check which Page is active.

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

回答by JeffO

The Value (which is the default) property of the tab control is the index of the page with the focus. It starts with zero.

选项卡控件的 Value(这是默认值)属性是具有焦点的页面的索引。它从零开始。

If TabCtl18.Value = 0 Then
  'this must be the first page