Button on my form does nothing

Snecia

Registered User.
Local time
Today, 11:37
Joined
Apr 5, 2013
Messages
12
Hi,

I've added a button to my form and in the On Click event I've added some code (by clicking the "...").

Here is my code:
Code:
Option Compare Database

Private Function DisplayReport()
    DoCmd.OpenReport List0, acViewNormal
    MsgBox "TEST"
End Function

Private Sub Command3_Click()
    Call DisplayReport
    MsgBox "DEBUG"
End Sub

I can't understand why nothing happens when I click the button. No message boxes and no report.

Thanks for your time,
 
When you add a button and add on an OnClick event associated with it, you have some choices. One of them is to launch a macro. The other is to launch VBA event code. You need to call your routines from the event before they will actually do something.

I see that you use VBA, so I'm going to orient my answer that way.

On the form design screen, assure that the "Properties" sheet is up. Select your button. Now, select the Events tab of the Properties sheet. Select the OnClick event. When you do, you get a Drop-Down button. Click that, select [Event Procedure], and click that. You SHOULD drop into the VBA editor. From there, you can add a call to whatever you want.

Note that Windows and Access both allow some level of control over how you launch things, via single click or double click for example. Therefore, you might have to play with it a bit. But your goal is to launch the VBA editor from the Properties/Events sheet associated with the button.

Since you can write VBA, you will be able to read what Access Wizards generate for a button-click event easily.
 
Ok I'm hoping someone can help me 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...
 
Try changing displayreport from a function to a sub and remove the call - but if you just want to open the report on clicking the button you don't actually need the separate function/sub, just put the docmd in your Command3_click sub.

Also, I presume List0 is a control on your form and the bound column is set to the column with the report names and you have selected a row in List0
 
Just seen your second post - if you are using 2007/10 just check that you have enabled vba - I've attached a short document to explain
 

Attachments

Users who are viewing this thread

Back
Top Bottom