Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Dec 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB AddControl (2000)

    I have created an user form in VBA for entering line items. I am using textboxes and add textboxes with the AddControl statement, if the line items exceed screen space. How does one access the events for each added control i.e. Click, Change, Enter, Exit etc?

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: VB AddControl (2000)

    You can right-click on the form
    view code
    in the left pulldown at the top of the pane
    select the object
    after the object is selected use the right pulldown to select the event

    This will create the sub.. EndSub sequence.
    You must fill in all the code, between the statements. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Steve

  3. #3
    New Lounger
    Join Date
    Dec 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB AddControl (2000)

    I appreciate the reply. However, I should explain that I am trying to access control events during runtime for a textbox that is created at the same runtime, not at design time.
    The textbox is created at runtime by clicking a command button. The textbox appears on the form, within a frame, with the focus set. I now want to access events for this new control, as they occur, while having not left runtime execution.
    VBA creates a name for this control at runtime, as it is created, and fires the "AddControl" event of the frame wherein the new control is contained. I now would like to access the "Click, Change, Exit & LostFocus" or other events for this new textbox while still in runtime.
    Below is the snippet that creates the texbox at runtime.
    '
    Private Sub cmdAddLine_Click()
    Dim MyCmd As Control
    NewTop = NewTop + 18
    NewLineNum = NewLineNum + 1
    '
    Set MyCmd = Frame1.Controls.Add("Forms.TextBox.1")
    With MyCmd
    .AutoSize = False
    .AutoTab = False
    .AutoWordSelect = True
    .Left = 78
    .Top = NewTop
    .Width = 30
    .Height = 14.75
    .BorderStyle = 1
    .SelectionMargin = False
    .TabKeyBehavior = False
    .SetFocus
    End With

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: VB AddControl (2000)

    Check out John Walkenbach He shows how to create form at runtime populate it and add the code.

    Steve

  5. #5
    New Lounger
    Join Date
    Dec 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB AddControl (2000)

    This is it! Thanks, however, how does one connect with the methods: .CodeModule, .CountOfLines, .InsertLines? Or are they intrinsic with a higher version than Excel 2000?

  6. #6
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: VB AddControl (2000)

    Set a reference in VBA to the VBA Extensibility library.

    In VBA editor (alt-F11)
    Tools -References
    check "Microsoft Visual Basic For Applications Extensibility" [I think it is 5-point-something for XL2000, XL97 has no version number]

    Steve

  7. #7
    New Lounger
    Join Date
    Dec 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB AddControl (2000)

    Much obliged. I will work with this. This is certainly what I was looking for.
    Any suggestions for getting more details about what this library contains & how to use it?

Posting Permissions

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