CommandButton Click Event not firing

R

Rob

Hello,

I have a routine which builds a form, adding CommandButtons depending on the
entries in some table. I built a class module KWButtonClass which has the
code I list below. It's supposed to run whenever a button on the built form
is pressed, but the Click Event isn't firing. Anyone know why?
(By adding additional code I can verify that the KWButtonClass objects are
in fact being instantiated.)

-------------------------------
KWButtonClass Code:


Public WithEvents KWButton as CommandButton

Private Sub KWButton_Click()
MsgBox ("Clicked!")
End Sub

----------------------

The code for the form I build reads as follows:

Dim ButtonArray() as New KWButtonClass

Private Sub Form_Load()

ReDim ButtonArray(1 to Me.Controls.Count)
For i = 1 to Me.Controls.Count 'the only controls on the form are KWButtons
Set ButtonArray(i).KWButton = Me.Controls(i-1)
Next i

End Sub
 
R

Rob

Some more information:
If I add an event handler sub into the form module, even (for example)
something trivial like:

Private Sub Command0_Click()

End Sub

then the event code in the class module will run. Thus if I built code like
that for all the buttons then I'd be in good shape. But of course the point
of the entire exercise was to avoid having to do that, plus I'd need to have
trusted access to the Visual Basic project (all those little code snippets
would have to be added when my process automatically builds the form) and I
can't guarantee that.

At this point, when I build one of these buttons, the button has no On Click
event procedure -- but shouldn't the OnClick procedure in the Class Module
fire anyway?

Thanks for any insights,
Rob
 
D

Dirk Goldgar

In
Rob said:
Some more information:
If I add an event handler sub into the form module, even (for example)
something trivial like:

Private Sub Command0_Click()

End Sub

then the event code in the class module will run. Thus if I built
code like that for all the buttons then I'd be in good shape. But of
course the point of the entire exercise was to avoid having to do
that, plus I'd need to have trusted access to the Visual Basic
project (all those little code snippets would have to be added when
my process automatically builds the form) and I can't guarantee that.

At this point, when I build one of these buttons, the button has no
On Click event procedure -- but shouldn't the OnClick procedure in
the Class Module fire anyway?

This is just a guess, but I think you must set the OnClick property of
each button to "[Event Procedure]" if you want to trap the event. Have
you done that?
 
R

Rob

Hmm. Not quite. I can certainly set the OnClick property to "[Event
Procedure]', but unlike when doing this using the properties window, doing
this in code doesn't launch the code builder, i.e. it doesn't create any code
like I list below. It just says the button should look for the xxx_Click
code in the form's module. Apparently since there's no such code, it doesn't
do anything. That's really kind of strange to me. One would think that if
you are able to create a button in code, then in that same code you ought to
be able to make the button actually do something!



Dirk Goldgar said:
In
Rob said:
Some more information:
If I add an event handler sub into the form module, even (for example)
something trivial like:

Private Sub Command0_Click()

End Sub

then the event code in the class module will run. Thus if I built
code like that for all the buttons then I'd be in good shape. But of
course the point of the entire exercise was to avoid having to do
that, plus I'd need to have trusted access to the Visual Basic
project (all those little code snippets would have to be added when
my process automatically builds the form) and I can't guarantee that.

At this point, when I build one of these buttons, the button has no
On Click event procedure -- but shouldn't the OnClick procedure in
the Class Module fire anyway?

This is just a guess, but I think you must set the OnClick property of
each button to "[Event Procedure]" if you want to trap the event. Have
you done that?

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

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top