I have noticed that when I create a Class Module for a Textbox and use that on my forms - by adding via VBA in the form init event - neither the Enter or Exit methods are available. Of course if I just add a textbox to the form they are.
I can get the DblClick method to work fine so my class is setup correctly and my form.init code is also ok.
When I look in the Object browser for MSForms.TextBox I see it doesn't have Enter or Exit methods and presume this is the reason.
There is no urgency for me on this because I noticed it when building my first form that uses my own classes for textbox - Fortunately for what I'm working on now - I don't actually need the Enter or Exit methods, but thought someone might know if there is a work-around because I may need them in the future and for textboxes they are very useful methods
Here is my Class Code named nxTxtV
Option Explicit
Public WithEvents oTxtV As MSForms.TextBox
Private Sub oTxtV_Enter()
' This method never fires
MsgBox "Hello World from the Enter Method"
End Sub
Private Sub oTxtV_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
' This method works fine
MsgBox "Hello World from the DoubleClick Method for " & oTxtV.Value
End Sub
and here's my form initialise code
Private Sub UserForm_Initialize()
Dim xItm As Control, i As Long
Dim dItm As nxTxtV ' nxTxtV is the name of my class
For i = 1 To 5
Set xItm = Me.Controls.Add("Forms.TextBox.1", "Column" & i, True)
With xItm
.Value = "P" & i
.AutoSize = False
.Font.Size = 9
.Width = 25
.Height = 250
.TextAlign = 2 ' Centred
.SpecialEffect = 0
.BackColor = RGB(255, 128, 0)
.WordWrap = True
.Left = 200 + (i * 27)
.Top = 5
.Enabled = True
.Visible = True
End With
Set dItm = New nxTxtV ' nxTxtV is the name of my class
Set dItm.oTxtV = xItm
CodedObjs.Add dItm ' CodedObjs is declared at module level (form level) as a Collection
Next i
End Sub
In short, can I get my class to react to Enter & Exit events ?
Addendum - the CodedObjs Declaration
Public CodedObjs As New Collection