I have a form with just one textbox (txtMyTextBox) which has the below code. I am trying to have the KeyPress event for the txtMyTextBox textbox triggered in the CControlEvent class. This is not happening due to some unknown reason.It is imperative for me to keep the collection object (ControlCollection) since I would like to have the KeyPress event triggered in the class for other textboxes.
What am I missing here?
Thanks in advance for your help
**************FORM CODE****************
Option Compare Database
Option Explicit
Private ControlCollection As Collection
Private Sub Form_Current()
Dim ctr As CControlEvent
Set ctr = New CControlEvent
Set ctr.setControl = txtMyTextBox
ControlCollection.Add ctr
End Sub
Private Sub Form_Load()
Set ControlCollection = New Collection
End Sub
****************************************
&&&&&&&&&&&&&&&&& CControlEvent Class Code &&&&&&&&&&&&&&
Option Compare Database
Option Explicit
Private WithEvents textbox1 As TextBox
Public Property Set setControl(ByVal aTextBox As TextBox)
Set textbox1 = aTextBox
End Property
Private Sub textbox1_KeyPress(keyascii As Integer)
textbox1.ForeColor = vbRed
End Sub
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&