Guys,
I have the userform below (sorry it isn't very clear). All controls on the multipage have been added at run-time.
UFPic.png
I have managed to get a handle on the textbox events using:
Class module
Public WithEvents oTxt As MSForms.Textbox
Private Sub oTxt_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim oCtrl As MSForms.Control
Set oCtrl = oTxt
Debug.Print "KeyDown" & " " & oCtrl.Name
End Sub
Private Sub oTxt_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim oCtrl As MSForms.Control
Set oCtrl = oTxt
Debug.Print "KeyPress" & " " & oCtrl.Name
End Sub
Private Sub oTxt_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim oCtrl As MSForms.Control
Set oCtrl = oTxt
Debug.Print "KeyUp" & " " & oCtrl.Name
End Sub
Private Sub oTxt_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim oCtrl As MSForms.Control
Set oCtrl = oTxt
Debug.Print "MouseDown" & " " & oCtrl.Name
End Sub
Private Sub oTxt_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim oCtrl As MSForms.Control
Set oCtrl = oTxt
Debug.Print "MouseUp" & " " & oCtrl.Name
End Sub
Userform module
Private m_arrTextboxes() As New clsTextBox
Private Sub UserForm_Initialize()
Dim oCtrl as MSForms.Control
Dim i as integer
'Create events for all dynamically added textbox controls.
i = 1
On Error Resume Next
For Each oCtrl In Me.Controls
If TypeName(oCtrl) = "TextBox" Then
ReDim Preserve m_arrTextboxes(i)
Set m_arrTextboxes(i).oTxt = oCtrl
i = i + 1
End If
Next oCtrl
End Sub
If the user wants to enter a date into a specific textbox, they can click into the textbox then click the 'dd/mm/yy' command button at the top right of the form which will display a datepicker. My problem is that I can't find a way to identify the last textbox control that was selected in order to enter the date.
Any ideas?
Joe