R
RadarEye
Hi you all,
I have created a tool in Excel 2003 which created dynamically a user
form. On this form there are several textboxes on which I would like
validation. The value entered must be a valid date. I am not allowed
to use any add-in like MSCAL.OCX. I would like to use the exit-event.
How can I dynamically add this event to the textboxes I have created
with:
With Me.Controls.Add("Forms.TextBox.1", "txtName" & strName, True)
.Top = 200
.Left = 100
.Height = 16
.Width = 50
.ControlSource = "Answers!B1"
.Font.Size = 8
End With
Ii have tried it with a class:
' class CtxtEvents
Option Explicit
Public WithEvents oTxt As MSForms.TextBox
Private Sub oTxt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If oTxt.Text <> vbNullString Then
If Not IsDate(oTxt.Text) Then
MsgBox "Geen datum"
Cancel = True
End If
End If
End Sub
Used as:
Dim oTxtEvnts As CtxtEvents
Set oTxtEvnts = New CtxtEvents
Set oTxtEvnts.oTxt = Me.Controls.Add("Forms.Textbox.1", "MijnText",
True)
With oTxtEvnts.oTxt
.Left = 200
.Top = 150
.Height = 16
.Width = 200
.Text = Format(Date, "dd-mm-yyyy")
End With
Is this possible?
I have created a tool in Excel 2003 which created dynamically a user
form. On this form there are several textboxes on which I would like
validation. The value entered must be a valid date. I am not allowed
to use any add-in like MSCAL.OCX. I would like to use the exit-event.
How can I dynamically add this event to the textboxes I have created
with:
With Me.Controls.Add("Forms.TextBox.1", "txtName" & strName, True)
.Top = 200
.Left = 100
.Height = 16
.Width = 50
.ControlSource = "Answers!B1"
.Font.Size = 8
End With
Ii have tried it with a class:
' class CtxtEvents
Option Explicit
Public WithEvents oTxt As MSForms.TextBox
Private Sub oTxt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If oTxt.Text <> vbNullString Then
If Not IsDate(oTxt.Text) Then
MsgBox "Geen datum"
Cancel = True
End If
End If
End Sub
Used as:
Dim oTxtEvnts As CtxtEvents
Set oTxtEvnts = New CtxtEvents
Set oTxtEvnts.oTxt = Me.Controls.Add("Forms.Textbox.1", "MijnText",
True)
With oTxtEvnts.oTxt
.Left = 200
.Top = 150
.Height = 16
.Width = 200
.Text = Format(Date, "dd-mm-yyyy")
End With
Is this possible?