简体   繁体   中英

VBA: Calling Function from Sub

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).

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?

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?

Your Sub Command3_Click contains no executable statements. Try

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".

命令

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...

Security Warning Some active content has been disabled. Click for more details.

...then be sure to click the "Enable Content" button.

你尝试过这个吗?

Call DisplayReport
  1. You pretend DisplayReport to be a function, but it actually returns nothing
  2. So, change it into a 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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