简体   繁体   English

如何在循环情况下使用 OpenArgs 打印多个报告?

[英]How can I use OpenArgs to print multiple reports in a loop situation?

I am slimming down my databases, eliminating duplicate reports where I can and creating better code.我正在精简我的数据库,尽可能消除重复报告并创建更好的代码。 I have one database that involves our welders and foremen.我有一个数据库,涉及我们的焊工和工头。 In this code, I can print a report for an individual foreman, which sends the string "strActive" through openargs The report looks at strActive and on the OpenForm action, sets the filter for active, inactive, or all welders, based on the string value passed through.在此代码中,我可以打印单个工头的报告,该报告通过 openargs 发送字符串“strActive” 报告查看 strActive 和 OpenForm 操作,根据字符串设置活动、非活动或所有焊工的过滤器值通过。

It works perfectly for the single page at a time code.它非常适合一个时间码的单个页面。 There, the user chooses a foreman from a list or enters the foreman's clock number.在那里,用户从列表中选择领班或输入领班的时钟编号。 The query the report is based on uses the global string "ForemanCLK" to only get results for that welder.报告所基于的查询使用全局字符串“ForemanCLK”来仅获取该焊工的结果。

Formerly, I had three reports;以前,我有三份报告; one for all welders, one for active welders, and one for inactive welders.一种适用于所有焊工,一种适用于活跃的焊工,一种适用于不活跃的焊工。

Previously, I would set a variable based on strActive and open the appropriate report using another variable in the code in place of the report name.以前,我会根据 strActive 设置一个变量,并使用代码中的另一个变量代替报告名称打开相应的报告。 The loop worked fine and opened the report 39 times, each time with a new foreman name and data.循环运行良好,打开报告 39 次,每次都使用新的工头姓名和数据。

I'm baffled as to why opening the report now, with an openarg, doesn't work.我很困惑为什么现在用 openarg 打开报告不起作用。 I only get the first foreman name, 39 times.我只得到第一个工头名字,39次。 I've verified that I get the foremanCLK variable of the different foremen by commenting out the docmd line and debug.print(ing) the various values needed by the form.我已经通过注释掉 docmd 行和 debug.print(ing) 表单所需的各种值来验证我获得了不同工头的 foremanCLK 变量。 The report simply doesn't load it correctly.该报告根本没有正确加载它。

Set rec = CurrentDb.OpenRecordset(sql)

    rec.MoveFirst

    For ctr = 0 To rec.RecordCount - 1
        ForemanCLK = rec(0).Value
        DoCmd.OpenReport "rptForeman", acViewNormal, , , , strActive
        'DoCmd.OpenReport "rptForeman", acViewNormal
    rec.MoveNext

    Next

The above code gets me many copies of the same foreman's report filtered by strActive上面的代码让我得到了许多由 strActive 过滤的同一个工头报告的副本

    For ctr = 0 To rec.RecordCount - 1
        ForemanCLK = rec(0).Value
        'DoCmd.OpenReport "rptForeman", acViewNormal, , , , strActive
        DoCmd.OpenReport "rptForeman", acViewNormal
    rec.MoveNext

But this gets me all the different foremen, except it is not filtered.但这让我得到了所有不同的工头,除了它没有被过滤。

I've tried passing in a Where clause.我试过传入一个 Where 子句。

acViewNormal, ,"[active]=" & True

and

acViewNormal, ,"[active]=" & False

and

acViewNormal, ,"[active]=" & True & " OR [active]=" & False

I did the same verification with the single report, and it filters correctly, but in the loop, it does not filter at all.我对单个报告做了同样的验证,它过滤正确,但在循环中,它根本不过滤。 It does, however give me the different foremen.然而,它确实给了我不同的工头。

The big question here is...这里的大问题是......

WHY?为什么? Does access not have enough time between reports to close it and therefore it doesn't perform the operations on the open event?访问是否在报告之间没有足够的时间来关闭它,因此它不会对打开的事件执行操作?

Any other ideas?还有其他想法吗?

You must close the report explicitly inside your loop: DoCmd.Close acReport, "rptForeman" .您必须在循环内明确关闭报告: DoCmd.Close acReport, "rptForeman" If OpenReport is called a second time on an already-open report, the object gets the focus in access, but it doesn't re-run the Open event.如果在已经打开的报表上第二次调用 OpenReport,该对象将获得访问焦点,但它不会重新运行 Open 事件。

Okay, I must hang my head in shame.好吧,我必须羞愧地低下头。

I error checked the hell out of that code above using every variable except strActive.我错误地使用strActive之外的每个变量检查​​了上面的代码。

When I added that to my debug.print line, it came up with nothing.当我将它添加到我的 debug.print 行时,它什么也没出现。 How can that be!?!!??怎么可能!?!!??

I simply forgot to set that at the beginning of the sub, like I did with the other action that opens a single report.我只是忘了在 sub 的开头设置它,就像我在打开单个报告的其他操作中所做的那样。 strActive is a global variable, but was not set at any other point in the code up until this piece. strActive一个全局变量,但在此之前没有在代码中的任何其他点设置。

Once this was added to the beginning of the sub, all worked fine.一旦将其添加到 sub 的开头,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM