vba 访问 - 报告打开,然后在打开表单关闭时隐藏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3971190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access - Report opens and then is hidden when opening form is closed
提问by webworm
I am using Access 2003 and I have a form that collects some filtering criteria for the report. Once the criteria is entered the user clicks and "OK" button and the report is launched using the following VBA.
我正在使用 Access 2003 并且我有一个表单来收集报告的一些过滤条件。输入条件后,用户单击“确定”按钮,然后使用以下 VBA 启动报告。
DoCmd.OpenReport "ReportName", acViewPreview
After the report is opened I issue the following command to close the form that collected the filtering criteria ...
打开报告后,我发出以下命令关闭收集过滤条件的表单...
Me.Close
The form closes however the report, which I wanted to stay open in the foreground, is hidden. Any idea why this is happening?
表单关闭,但是我想在前台保持打开状态的报告被隐藏了。知道为什么会这样吗?
回答by David-W-Fenton
When all else fails with forms and reports coming to the front at the desired time, you can do it explicitly with DoCmd.SelectObject:
当所有其他方法都失败并且表单和报告在所需时间出现在前面时,您可以使用 DoCmd.SelectObject 显式执行此操作:
DoCmd.OpenReport "rptMyReport", acViewPreview
DoCmd.SelectObject acReport, "rptMyReport"
DoCmd.Close acForm, Me.Name
If that doesn't work, there's something else involved, like forms or reports opened with the acDialog switch, or with forms/reports having the Modal or Popup properties set to True.
如果这不起作用,则涉及其他内容,例如使用 acDialog 开关打开的表单或报告,或者将 Modal 或 Popup 属性设置为 True 的表单/报告。
Or, there might be a timer running somewhere that's causing something to happen that's grabbing focus.
或者,可能有一个计时器在某处运行,导致某些事情发生并引起了人们的注意。
回答by Paco Villacastin
Try setting the Report property Modal to Yes (in Other Properties).
尝试将报告属性模态设置为是(在其他属性中)。
回答by Rspaeth
I struggled with this for a couple days. It seems you need to close the current window and then open the report in Print Preview.
我为此挣扎了几天。看来您需要关闭当前窗口,然后在打印预览中打开报告。
I have a button on a pivotchart embedded in a Report. (Access2010) When i tried to just print the report- any filtering on the pivot chart didn't get carried over to the "DoCmd.Printout" command.
我在报表中嵌入的数据透视图上有一个按钮。(Access2010) 当我试图只打印报告时 - 数据透视图上的任何过滤都没有转移到“DoCmd.Printout”命令中。
It was suggested I use open the print preview window, but it never received focus. I had to click off screen then back toe the print preview window. The code below seems to correct this.
有人建议我使用打开打印预览窗口,但它从未获得焦点。我不得不点击屏幕外,然后回到打印预览窗口。下面的代码似乎纠正了这一点。
Private Sub Command1_Click()
DoCmd.Save
DoCmd.Close
DoCmd.OpenReport "R-MyReport", acViewPreview
回答by Fink
Does closing the form, then opening the report work? I'm guessing it has to do with the focus being shifted back and forth between the objects.
关闭表单,然后打开报告是否有效?我猜这与焦点在物体之间来回移动有关。
EDIT
编辑
Your code should look something like this:
您的代码应如下所示:
Private Sub Command0_Click()
'your code here
DoCmd.Close acForm, Me.Name
DoCmd.OpenReport "Report1", acViewPreview
End Sub
Also, there is no native close function as others have pointed out.
此外,正如其他人指出的那样,没有本机关闭功能。