2011-05-26 47 views
1

我在MS Access 2011中創建了一個表單,其中有一個名爲TabCtl18的頂部的選項卡控件,其中3個選項卡是page1,page2,page3。 在page1選項卡下還有另外3個其他選項卡page11,page22,page33,在三個選項卡下分別有3個報告檢查MS Access窗體中的哪個選項卡被點擊/激活

現在我希望當用戶點擊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 

回答

2

價值(這是默認設置)選項卡控件的屬性與焦點的頁面的索引。它從零開始。

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

給選項卡控件添加有意義的名稱並使用它們會更好,因爲如果添加選項卡,名稱不會更改,但選項卡索引可以更改。 – 2011-05-28 22:16:31

2

基於由@大衛突出問題,這裏是檢查選擇的TabPage的名稱的方式。

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

此外,您可以使用此代碼Tab控制Click事件檢查哪個頁面是有效的。

相關問題