What am I missing?

S

Shael

I've tried several code iterations behind the On Click event of a command
button but am not getting any success. Then I wondered if the code was even
being executed. So now I have a command button on a form, and in the On Click
event of that button I have the following code:

Private Sub cmdShowBatterStats_Click()
MsgBox "Hello"
End Sub

When I open the form and click on the button, no message box is displayed.
Can someone tell me what I'm missing. Why is the code in the On Click event
not being invoked?
 
S

Shael

Yes, I see [Event Procedure] (without quotes).

Dirk Goldgar said:
In
Shael said:
I've tried several code iterations behind the On Click event of a
command button but am not getting any success. Then I wondered if the
code was even being executed. So now I have a command button on a
form, and in the On Click event of that button I have the following
code:

Private Sub cmdShowBatterStats_Click()
MsgBox "Hello"
End Sub

When I open the form and click on the button, no message box is
displayed. Can someone tell me what I'm missing. Why is the code in
the On Click event not being invoked?

When you open the form in design view, select the button, bring up its
property sheet, got to the Event tab, and look at the line that says "On
Click", what do you see? Does it say "[Event Procedure]" (without the
quotes)?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

In
Shael said:
I need to compile this code?

Access will normally compile on demand, unless you have turned off that
option. But explicitly compiling (via menu items Debug -> Compile)
will turn up coding errors that may possibly be preventing your code
from compiling. I'd certainly try that.

BTW, what version of Access are you using? I don't recall if you've
mentioned that.
 
S

Shael

I'm using Access 2007. When I click on the Debug menu item, the first menu
item is Compile DDHB, which is greyed out.
 
D

Dirk Goldgar

In
Shael said:
I'm using Access 2007. When I click on the Debug menu item, the first
menu item is Compile DDHB, which is greyed out.

That means that the project is compiled, so that's not the problem. I'm
not using Access 2007, so I can't check things out here, but I seem to
recall that the new security model disables VBA code by default. You
may have to find an option or setting to enable VBA. Check in options
related to security or trust.
 
F

Fred Boer

Dear Shael:

I am no expert in Access 2007, but the following steps will allow you to set
up your file in a "Trusted Location" so that VBA will run:

Click on the "Office Button" in the top left corner.
Click on "Access Options".
Click on "Trust Center".
Click on "Trust Center Settings..."
Click on "Add new Location..."
Enter the path to the location of your file.

HTH

--
Fred Boer - Amateur Access Enthusiast
Interests: Library software / Z39.50 / Web Services
Freeware Small Library Application available here:
http://www3.sympatico.ca/lornarourke/
 
Top