LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Dynamic Event handler wanted.

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?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event handler VBA Noob[_4_] Excel Programming 4 April 26th 06 03:49 PM
Event handler in a cell Man Utd Excel Programming 3 June 15th 05 07:44 AM
Global event handler?? [email protected] Excel Programming 1 October 23rd 04 05:31 PM
different IDispatch in event handler Dirk[_2_] Excel Programming 0 January 23rd 04 11:04 PM
Cell Event Handler David Excel Programming 3 January 19th 04 04:51 PM


All times are GMT +1. The time now is 03:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"