VBA:从子调用函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15864879/
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
VBA: Calling Function from Sub
提问by Juicy
Private Function DisplayReport()
DoCmd.OpenReport List0, acViewNormal
End Function
Private Sub Command3_Click()
End Sub
I'm trying to figure out how to call DisplayReport() when Command3 is clicked (This is in Access 2010).
我试图弄清楚如何在单击 Command3 时调用 DisplayReport()(这是在 Access 2010 中)。
I'm hoping this will open the report that is currently selected in List0 (a list box). Is this the proper way of doing it?
我希望这将打开当前在 List0(一个列表框)中选择的报告。这是正确的做法吗?
EDIT: I think I understand from reading somewhere else that this is a "Trusted Location" issue? What does this mean and how can I fix this?
编辑:我想我从其他地方的阅读中了解到这是一个“受信任的位置”问题?这是什么意思,我该如何解决?
回答by Gord Thompson
Your Sub Command3_Click
contains no executable statements. Try
您的不Sub Command3_Click
包含可执行语句。尝试
Private Sub Command3_Click()
DisplayReport
End Sub
Also, verify that the On Click
event property of the button is associated with a handler. If that line is empty, click the ellipsis button [...] and choose "Code Builder".
此外,验证On Click
按钮的事件属性是否与处理程序相关联。如果该行为空,请单击省略号按钮 [...] 并选择“代码生成器”。
Edit
编辑
If you've made those changes and the event still does not fire, then close and re-open the database. If you see a warning near the top of the Access window that says...
如果您进行了这些更改并且事件仍未触发,则关闭并重新打开数据库。如果您在 Access 窗口顶部附近看到一条警告,指出...
Security WarningSome active content has been disabled. Click for more details.
安全警告某些活动内容已被禁用。点击了解更多详情。
...then be sure to click the "Enable Content" button.
...然后一定要点击“启用内容”按钮。
回答by Alberto De Caro
- You pretend DisplayReport to be a function, but it actually returns nothing
- So, change it into a Sub:
- 你假装 DisplayReport 是一个函数,但它实际上什么都不返回
- 因此,将其更改为 Sub:
Private Sub DisplayReports DoCmd.OpenReport List0, acViewNormal End Sub
Hence call it from the click handler:
因此从点击处理程序调用它:
Private Sub Command3_Click() call DisplayReport End Sub
回答by Juicy
Ok, this is a problem I have with Access 2010. The problem was that my database was not trusted. I managed to change this setting and now the code runs fine.
好的,这是我在 Access 2010 中遇到的问题。问题是我的数据库不受信任。我设法更改了此设置,现在代码运行良好。
回答by Harkonnen
Did you try this ?
你试过这个吗?
Call DisplayReport