userform_keypress event
Patrick Molloy wrote:
You can do this using a class module ...
1) add a new CLASS MODULE, and name it clsControl
<<snip
5) add a standard code moduke withthis code:
Option Explicit
Sub PastReply(msg As String, cbx As Control)
With UserForm1
.Label1.Caption = msg
Set .ctrl = cbx
End With
End Sub
I may have a reputation for being a standard module and public variable
sceptic but IMO hard coding a public reference to Userform1 and having
the class call a method in a standard module doesn't fit this scenario.
What if I wanted to use the same class for more than one userform in
the project? What if I used more than one instance of Userform1 in the
project?
I think a better approach would be for the class to raise an event and
for the implementation code (Label1.Caption = msg etc) to appear in the
userform's code module, making the code easier to reuse with the same
and/or other projects Why the standard module approach?
Jamie.
--
|