使用 Access 2003 VBA,我希望能够在屏幕上显示报告,而不是打印出来。但这不起作用
预先感谢您提供的任何帮助。 我正在使用案例声明来确定要打印哪个报告。我已确定选择了正确的案例陈述。下面是 case 语句:
Public Function RunAll(Vvar As Integer)
Select Case Vvar
Case 1
'Case Me.frmeReports.Value = 1
DoCmd.OpenReport "rptClientDev", acViewPreview
Case 2
'Case Me.frmeReports.Value = 2
DoCmd.OpenReport "rptNetworking", , , , acViewPreview
Case 3
'Case Me.frmeReports.Value = 3
DoCmd.OpenReport "rptSpeaking", , , , acViewPreview
Case 4
'Case Me.frmeReports.Value = 4
DoCmd.OpenReport "rptArticle", , , , acViewPreview
End Select
End Function
该函数从以下子例程中调用:
Private Sub cmdOK_Click()
If Me.ChkRunOne.Value = -1 Then
strAttName = Me.cmbAttyName.Value
vReportChoice = Me.frmeReports.Value
RunOnce (vReportChoice)
DoCmd.Close
DoCmd.OpenForm ("frmMainMenu")
Else
vReportChoice = Me.frmeReports.Value
RunAll (vReportChoice)
DoCmd.Close
DoCmd.OpenForm ("frmMainMenu")
End If
End Sub
报告正确打印,具有正确的值。问题是我不希望它们打印出来,我希望它们出现在屏幕上。您可以通过案例 1 语句看到,我尝试在参数之间使用更少的逗号,但结果是相同的。打印报告,然后关闭数据库。我在这里完全困惑了。
-谢谢
Thank you in advance for any help you can provide.
I am using a case statement to determine which report to print. I have determined that the correct case statement is chosen. Here is the case statement:
Public Function RunAll(Vvar As Integer)
Select Case Vvar
Case 1
'Case Me.frmeReports.Value = 1
DoCmd.OpenReport "rptClientDev", acViewPreview
Case 2
'Case Me.frmeReports.Value = 2
DoCmd.OpenReport "rptNetworking", , , , acViewPreview
Case 3
'Case Me.frmeReports.Value = 3
DoCmd.OpenReport "rptSpeaking", , , , acViewPreview
Case 4
'Case Me.frmeReports.Value = 4
DoCmd.OpenReport "rptArticle", , , , acViewPreview
End Select
End Function
This function is called from the following subroutine:
Private Sub cmdOK_Click()
If Me.ChkRunOne.Value = -1 Then
strAttName = Me.cmbAttyName.Value
vReportChoice = Me.frmeReports.Value
RunOnce (vReportChoice)
DoCmd.Close
DoCmd.OpenForm ("frmMainMenu")
Else
vReportChoice = Me.frmeReports.Value
RunAll (vReportChoice)
DoCmd.Close
DoCmd.OpenForm ("frmMainMenu")
End If
End Sub
The reports print correctly, with the right values. The problem is that I don't want them to print, I want them to come up on the screen. You can see with the Case 1 statement that I tried using fewer commas between arguments, but the result is the same. The report prints and then the database closes. I'm totally confused here.
-Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
语法来自: http://msdn.microsoft.com /en-us/library/bb238032(v=office.12).aspx,2003年也是一样。
所以这些都是
错误的,逗号太多了。
第一个是对的。
Syntax from: http://msdn.microsoft.com/en-us/library/bb238032(v=office.12).aspx, 2003 is the same.
So all these
are wrong, there are too many commas.
The first one is right.
这是关于您的第二个注释 - 关于数据库意外关闭的注释:
我认为这可能是由于不小心使用
DoCmd.Close
引起的:当您在没有任何参数的情况下调用此方法时,它会关闭 当前活动的窗口不一定是您真正想要关闭的窗口。在这种特殊情况下,您在调用 DoCmd.Close 之前打开了一大堆报告窗口 - 您认为哪个窗口在调用时会变为活动状态? ;-)在调用 DoCmd.Close 时,最好始终使用特定窗口(例如表单)引用(请参阅 此 MSDN 页面 了解更多详细信息)。
This is about your secondary note - the one about unexpected closure of the database:
I think this might be caused by careless use of
DoCmd.Close
: when you call this method without any arguments it closes the currently active window which is not necessarily the window you really wanted to close. In this particular case you're opening a whole bunch of report windows just before callingDoCmd.Close
- which window do you think becomes active by the time of call? ;-)It's a good practice to always use specific window (e.g. form) reference when calling
DoCmd.Close
(see this MSDN page for more details).