【问题标题】:How to Fix Run Time Error如何修复运行时错误
【发布时间】:2015-10-31 05:06:39
【问题描述】:

我有一个访问程序,让用户单击将生成积压报告并显示它的按钮,然后将该报告输出到此路径上的文件夹:
S:\ALC MASTER\Month End Reports - 2015\Senior Management\2015 Backlog Report

但由于某种原因,即使文件被输出到该文件夹​​,即使出现错误,我也会不断收到运行时错误。我只想知道是否有办法抑制该错误。

这是我的代码:

Dim MonthStart As Integer
Dim MonthEnd As Integer

For i = 1 To DLookup(DMax("[rsu]", "[RSU totals]", ""), "[RSU totals]", "") Step 1
    If DCount("*", "[RSU totals]", "[rsu] = " & i) > 0 Then

        If Date < "#8/01/" & Year(Now) & "#" Then
            setDate = "7/01/" & Year(Now)
            rptName = "Sales Forecast Detail - Jan-Jun"
        Else
            setDate = "13/01/" & Year(Now)
            rptName = "Sales Forecast Detail - Jul-Dec"
        End If

        fileDirName = "S:\ALC MASTER\Month End Reports - " & Year(Now) & "\" & "Senior Management" & _
        "\" & Year(Now) & " Backlog Report" & "\" & Format(DateAdd("m", -1, Date), "mm") & "-" & _
        Format(DateAdd("m", -1, Date), "mmm") & " - " & Format(DateAdd("m", -1, setDate), "mmm") & ".pdf"

        DoCmd.OpenReport rptName, acViewReport, , "[rsu] = " & i
        Reports(rptName).ReportFooter.Visible = Flase
        DoCmd.OutputTo acOutputReport, rptName, "PDF Format(*.pdf)", fileDirName, True
        DoCmd.Close acReport, rptName

    End If
Next

【问题讨论】:

  • 你得到什么运行时错误?
  • 运行一个名为 RSU totals 的查询,对记录器进行计数,然后为找到的每条记录运行循环。

标签: ms-access error-handling vba


【解决方案1】:

似乎我的问题是我正在循环浏览不存在的报告。取出 For 循环,最初的 If 语句就起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    相关资源
    最近更新 更多