Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Event procedures for controls added with Controls.Add

I need to create event procedures for controls added with Controls.Add.
The following approach was suggested:

Private Sub UserForm_Activate()
Dim Ct As Control, StartLine as long

Set Ct = Me.Controls.Add("Forms.TextBox.1", "txtNew" , True)
With ActiveWorkbook.VBProject.VBComponents("UserForm1") .CodeModule
StartLine = .CreateEventProc("Change", Ct.Name) + 1
End With

But I get a runtime error on the .CreateEventProc call - Error 57017 "Event
handler is invalid"

Where have I gone wrong? Are there any other approaches (such as control
arrays in VB6)

Many thanks,
--
John Austin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Event procedures for controls added with Controls.Add

Another complication: When the workbook is protected, the line:
With ActiveWorkbook.VBProject.VBComponents("UserForm1") .CodeModule
causes a run-time error. I really need to trap the TextBox change events
with the VBA code protected.

"John Austin" wrote:

I need to create event procedures for controls added with Controls.Add.
The following approach was suggested:

Private Sub UserForm_Activate()
Dim Ct As Control, StartLine as long

Set Ct = Me.Controls.Add("Forms.TextBox.1", "txtNew" , True)
With ActiveWorkbook.VBProject.VBComponents("UserForm1") .CodeModule
StartLine = .CreateEventProc("Change", Ct.Name) + 1
End With

But I get a runtime error on the .CreateEventProc call - Error 57017 "Event
handler is invalid"

Where have I gone wrong? Are there any other approaches (such as control
arrays in VB6)

Many thanks,
--
John Austin

Reply
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
how can I trap the change event (Tab Press key) of these controls Padam Excel Worksheet Functions 1 August 10th 06 03:59 PM
How to manipulate controls added at run-time thomasdavisz Excel Worksheet Functions 0 January 16th 06 11:26 PM
how to access programatically added controls don bowyer Excel Programming 3 August 8th 04 11:28 AM
Changing Event Subs of Controls On Air Haldun Alay[_3_] Excel Programming 3 October 30th 03 09:45 AM
Same event procedure for multiple controls Mikhail Excel Programming 1 October 13th 03 03:23 PM


All times are GMT +1. The time now is 10:15 AM.

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

About Us

"It's about Microsoft Excel"