PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Event doesn't fire-VBForums
Results 1 to 3 of 3

Thread: Event doesn't fire

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    4

    Event doesn't fire

    Hi

    I'm adding a CommandButton to my startup form at runtime.

    set cmd1 = Form1.Controls.Add("VB.CommandButton", cmdnew)

    It is displayed correctly. However, the relating event

    Sub cmdnew_Click()
    ...
    End Sub

    won't fire. What am I doing wrong? All I could find out is that it's probably related to the control's lifetime. Is there a better way to create controls dynamically? When I use the New Keyword

    Dim cmd1 As CommandButton
    cmd1 = New CommandButton

    I always get an error message.

    Thanks for your help.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,092
    Yeah, you can't New a control, you need to get the return of an Add function like you are doing now.

    Have you declared your button variable using the WithEvents keyword?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,100

    Re: Event doesn't fire

    Originally posted by stk
    ...Is there a better way to create controls dynamically? ...
    "Better" is debatable, but here is another way. At design time put a command button on the form, set its Index property to 0 and its Visible property to False. To show that button you obviously just set its Visible property to True. To create and show a second or subsequent button you

    VB Code:
    1. Load Command1(1)
    2. Command1(1).Visible = True
    3. Command1(1).Top = ' Use Top and Left (or Move) to place it where you want 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
  •  



Featured


Click Here to Expand Forum to Full Width