无法使用更新的参数集从VB关闭或刷新访问报告 [英] Access report cannot be closed or refreshed from VB with updated parameter set

查看:105
本文介绍了无法使用更新的参数集从VB关闭或刷新访问报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击表单的按钮会打开一个包含数据的访问报告.这些参数与对SQL存储过程的传递查询一起使用,该存储过程返回记录.该报告没有提出莫代尔,我希望它保持这种状态.但是,如果用户在返回表单之前未关闭报表并尝试设置新参数,则报表将在后台保持打开状态,并且在单击按钮后,报表将使用旧的参数和数据而脱颖而出,并且不会刷新带有新的参数/数据.

A form's button click opens an access report that comes up with data. The parameters are used with a pass-through query to an SQL stored procedure which returns records. The report does not come up Modal and I would like it to remain that way. However, if the user does not close the report before going back to the form and tries to set new parameters, the report remains open in the background and upon the button click the report is brought to the fore with old parameters and data and not refreshed with new parameters/data.

一个选项是对报告采用模态"功能,但由于用户必须主动关闭报告,因此需要进行粗略的转换.另一个选择是在重试期间关闭报告,这是我一直在尝试的方法.我已经尝试过:

One option is to go Modal with the report but that makes for rough transitions with the user having to actively close the report. The other option is to close the report during retries which is what I have been trying. I have tried:

    If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
        DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo

在几个不同的位置:_MousedDown,作为_Click中的第一个If,以及_BeforeInsert.每次CurrentReport.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded在第二遍过程中都将其设置为false时,报表位于背景中,并且表单将与下一个表单一起使用,并尝试下一个新参数.同样在第二次尝试中,.strReportP1行不完整,因此.OpenReport行失败并显示SQL错误.这是_Click事件:

in several different locations: _MousedDown, as the first If in the _Click, and _BeforeInsert. Each time CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded comes up false during the second pass when the report is sitting in the background and the form is being reworked with the next tries new parameters. Also during the second attempt the .OpenReport line fails with an SQL error because strSQLP1 is incomplete. Here's the _Click event:

Private Sub btnPreviewP1_Click()

    If (Me.txtToDateP1 < Me.txtFromDateP1) Then
        MsgBox ("The From Date must occurr before the To Date!")
    End If

    Dim strFromDateHMS  As String
    Dim strToDateHMS    As String
    Dim strSQLP1    As String
    Dim strOpenArgs As String

    strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
    strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1

    strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1

    strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1

    ' This line is all that's needed to modify the PT query
    CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1

    DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs

End Sub

和.AllReports当前所在的_MouseDown:

And the _MouseDown where the .AllReports is currently:

Private Sub btnPreviewP1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If CurrentProject.AllReports(rpt_ptq_uspWorkCentreReport).IsLoaded Then
        DoCmd.Close acReport, rpt_ptq_uspWorkCentreReport, acSaveNo
    End If
End Sub

这是Report_Open:

This is the Report_Open:

Private Sub Report_Open(Cancel As Integer)
    Dim SplitOpenArgs() As String
    SplitOpenArgs = Split(Me.OpenArgs, "|")
    Me.lblFromDate.Caption = SplitOpenArgs(1)
    Me.lblToDate.Caption = SplitOpenArgs(2)
    Me.lblWC.Caption = SplitOpenArgs(3)
    Me.lblShift.Caption = SplitOpenArgs(4)
End Sub

推荐答案

为什么不只是在OpenReport之前关闭报告?我修改了您的代码:

Why not just close report before OpenReport? I modified your code:

Private Sub btnPreviewP1_Click()

    If (Me.txtToDateP1 < Me.txtFromDateP1) Then
        MsgBox ("The From Date must occurr before the To Date!")
    End If

    Dim strFromDateHMS  As String
    Dim strToDateHMS    As String
    Dim strSQLP1    As String
    Dim strOpenArgs As String
    Dim R

    strFromDateHMS = Format(Me.txtFromDateP1, "yyyy-mm-dd") & " " & Me.cboFromHourP1 & ":" & Me.cboFromMinuteP1 & ":" & Me.cboFromSecondP1
    strToDateHMS = Format(Me.txtToDateP1, "yyyy-mm-dd") & " " & Me.cboToHourP1 & ":" & Me.cboToMinuteP1 & ":" & Me.cboToSecondP1

    strSQLP1 = "exec dbo.uspWorkCentreReport '" & strFromDateHMS & "','" & strToDateHMS & "','" & strWCP1 & "'," & strShiftP1

    strOpenArgs = Me.RecordSource & "|" & strFromDateHMS & "|" & strToDateHMS & "|" & strWCP1 & "|" & strShiftP1

    ' This line is all that's needed to modify the PT query
    CurrentDb.QueryDefs("ptq_uspWorkCentreReport").SQL = strSQLP1

    ' Check if report is open and close it without saving:
    For Each R In Reports
        If R.Name = "rpt_ptq_uspWorkCentreReport" Then
            DoCmd.Close acReport, "rpt_ptq_uspWorkCentreReport", acSaveNo
            Exit For
        End If
    Next R

    DoCmd.OpenReport "rpt_ptq_uspWorkCentreReport", acViewReport, , , , strOpenArgs

End Sub

这篇关于无法使用更新的参数集从VB关闭或刷新访问报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆