+ Reply to Thread
Results 1 to 2 of 2

Event procedures for controls added with Controls.Add

  1. #1
    John Austin
    Guest

    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. #2
    John Austin
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1