2014-09-05 91 views
0

我有一個嵌入到包含文本框和按鈕的表單中的報表。MS Access,刷新嵌入到表單中的報表

我的願望是更新報表上的過濾器並重新查詢並刷新表單中的報表。我對訪問中使用VBA不是很熟悉,所以我可能完全脫離了我試圖做到這一點的基礎。

單擊generateExhib按鈕時觸發的事件如下。

作爲子窗體/子報表嵌入的報表被命名爲TagReport。

Private Sub GenerateExhib_Click() 



    If (generatePrintedExhib.Value = False) Then 
     Me.TagReport.Application.DoCmd.SetFilter WhereCondition:="[Exhibitor ID] =" + ExhibitorNumber.Value + " AND [UDEntry-CheckBox1] = false" 
    Else 
     Me.TagReport.Application.DoCmd.SetFilter WhereCondition:="[Exhibitor ID] =" + ExhibitorNumber.Value 
    End If 


    Me.TagReport.Report.Application.DoCmd.Requery 
    Me.TagReport.Report.Application.DoCmd.RefreshRecord 


End Sub 
+0

不知道這是罪魁禍首,所以我會把它作爲評論發佈,但是你爲什麼要經歷「Me.TagReport.Report.Application.DoCmd.Requery'的整個討論,而不是僅僅是'Me.TagReport。 Requery'? – Aiken 2014-09-08 08:14:44

回答

0

我創建了一個帶有嵌入式報表的小測試表單,一個帶過濾值的組合框和一個刷新按鈕。在按鈕的單擊事件中,我添加了以下代碼:

Private Sub cmdRefresh_Click() 
    Dim filter As String 

    filter = "CardCode = '" & Me.cmbFilter.Value & "'" 

    '"subform_rpt" is the specific name of the embedded report. 
    DoCmd.ApplyFilter "Filter", filter, "subform_rpt" 

End Sub 

對我來說工作起來很不錯。我希望這將有所幫助。

+0

此外,如果您是新手,如果此答案解決了您的問題,請單擊旁邊的複選標記將其標記爲答案。如果你覺得有幫助,至少應該對它投票。 – 2014-09-05 22:46:29