0
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?

4 Answers 4

1

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

cmd

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunatly that's exactly how I have it set up yet nothing happens. I tried something simpler and it's not working. 1) I created a new form 2) I added a button to it 3) On the On Click event I selected Code Builder 4) Added MsgBox "Hello" 5) Saved, went to Form view and click the button, nothing happens There is obviously something I'm not getting here...
@user2018084 That's strange. Create a new, empty database and try those exact same steps. If it works in the new database then your existing database may need a /decompile.
@user2018084 I have updated my answer re: "[un-]trusted documents".
0

Did you try this ?

Call DisplayReport

4 Comments

Yes, I did but it doesn't do anything when I click on Command3. Even if I add MsgBox "DEBUG" in the DisplayReport function, nothing happens.
@user2018084: Did you set Command3's Click property to [Event Procedure]? Just adding Command3_Click is not enough...
Yes it is set to [Event Procedure]. I clicked on the "..." to add this
@user2018084 : My code should be called from your handler Command3_Click() of course.
0
  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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.