Hi
I've got this code (which I can't remember where from now, but I don't claim to have done it).
Basically I have a class event that works for all controls on any userform.
Its all working fine but I can't add an event to trap the click or mouse move of the userform itself.
Basically so when the cursor moves away from a control the label clears.
User Form Code
And here is the class Module
Any help appreciated...
Thanks
I've got this code (which I can't remember where from now, but I don't claim to have done it).
Basically I have a class event that works for all controls on any userform.
Its all working fine but I can't add an event to trap the click or mouse move of the userform itself.
Basically so when the cursor moves away from a control the label clears.
User Form Code
Code:
Option Compare Database
Option Explicit
'Define a collection and initialise the commandbutton event class
Private col As New Collection
Private newCmd As New clsEvents
Private Sub Form_Close()
Set col = Nothing
Set newCmd = Nothing
End Sub
Private Sub Form_Load()
' load all the commandbuttons of the form to one Eventhandler
Dim ctl As Control
' loop through all controls
For Each ctl In Me.Controls
'check if control is a commandbutton
'set a new reference to the new Eventclass
Set newCmd = New clsEvents
'store the commandbutton to the eventclass
Set newCmd.CmdBtn = ctl
'store the eventclass in a collection to keep them alive
col.Add newCmd, ctl.Name
'End If
Next ctl
End Sub
And here is the class Module
Code:
Option Compare Database
Option Explicit
'catch the event of Commandbuttons
Private WithEvents C0 As SubForm
'Private WithEvents C1 As CheckBox
'Private WithEvents C2 As ComboBox
Private WithEvents C3 As CommandButton
'Private WithEvents C4 As Frame
Private WithEvents C5 As Label
'Private WithEvents C6 As Image
'Private WithEvents C7 As ListBox
'Private WithEvents C8 As MultiPage
Private WithEvents C9 As OptionButton
'Private WithEvents C10 As ScrollBar
'Private WithEvents C11 As SpinButton
'Private WithEvents C12 As TabStrip
Private WithEvents C13 As TextBox
'Private WithEvents C14 As ToggleButton
Private WithEvents C15 As Form
Dim myFrm As Form
Dim myObj As Object
Dim myCtl As Object
Private ParentForm As Object
'which commandbutton should have a common Eventhandling
Public Property Set CmdBtn(c As Object)
Set ParentForm = c.Parent
Select Case TypeName(c)
Case "Userform": Set C0 = c
Case "CommandButton": Set C3 = c
Case "Label": Set C5 = c
Case "OptionButton": Set C9 = c
Case "TextBox": Set C13 = c
Case Else: Exit Property
End Select
Set myObj = c
c.OnClick = "[Event Procedure]"
c.OnMouseMove = "[Event Procedure]"
On Error Resume Next
c.GotFocus = "[Event Procedure]"
On Error GoTo 0
End Property
Public Property Set UsrFrm(c As Form)
Set ParentForm = c
Set C15 = c
Set myFrm = c
c.OnClick = "[Event Procedure]"
c.OnMouseMove = "[Event Procedure]"
End Property
Private Sub Class_Terminate()
Set C0 = Nothing
Set C3 = Nothing
Set C5 = Nothing
Set C13 = Nothing
Set C15 = Nothing
End Sub
Private Sub C3_Click()
ParentForm.Label1.Caption = "You clicked: " & myObj.Name & " with Caption " & myObj.Caption
End Sub
Private Sub C3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ParentForm.Label1.Caption = "You're over: " & myObj.Name & " with Caption " & myObj.Caption
End Sub
Private Sub C5_Click()
ParentForm.Label1.Caption = "You clicked: " & myObj.Name & " with Caption " & myObj.Caption
End Sub
Private Sub C5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
ParentForm.Label1.Caption = "You're over: " & myObj.Name & " with Caption " & myObj.Caption
End Sub
Any help appreciated...
Thanks