必须刷新访问报告才能显示数据

时间:2017-11-11 20:36:09

标签: vba ms-access access-vba ms-access-reports

我有一个按钮,当按下该按钮时,会打开关于该表单中所选记录的报告。这是按钮的代码:

blnSave = MsgBox("Are you sure you want to exit this student?", vbYesNo, "Exit Confirmation")
If blnSave = True Then
            DoCmd.OpenReport "rptExitNotice", acViewPreview, , "[BehaviourID]=" & Me.BehaviourID
            DoCmd.Close acForm, "frmExitStudent"
            End If

当表单关闭并且报表打开时,报表中的所有字段都是空白的: Empty Report 按F5时,数据显示完美: Complete Report

我尝试在打开,无数据和激活事件中放入Me.Refresh,DoCmd.Requery和DoCmd.Refresh,但是它们会出现以下错误: Method or data member not found The command or action "Refresh Record" isn't available now

如何让报告第一时间显示数据? 按钮的代码有问题吗? 或者我应该在不同的事件中添加Me.Refresh或类似的东西吗?

1 个答案:

答案 0 :(得分:0)

我在On Load,On Open等中废弃了代码,并创建了一个定时器为1000的表单,timer事件执行此代码:

Private Sub Form_Timer()
Dim rpt As Report

With Reports
    ' Iterate over all open reports...
    For Each rpt In Reports
        rpt.Requery
    Next
End With
lblStatus.Caption = "Generation Complete"
DoCmd.Close acForm, "frmRefreshReport"
End Sub

表单刷新报告然后关闭。有一个状态标签可以在刷新完成后更改文本(使最终用户看起来更好)。报表打开时窗体将打开,因此报表将由表单刷新,然后自动关闭,从而保存用户按下F5。 资料来源:How to automatically reload a report in MS Access?