VB6 Anyone? Adding Click event for Dynamically created button?

Discussion in 'Programming' started by shahilroyhere, Apr 12, 2011.

  1. #1
    How to add the click event for a dynamically created button?
    Let's say I have created a button in runtime like this -
    Set ctlCmd1 = Me.Controls.Add("VB.CommandButton", "ctlCmd0")
    ctlCmd1.Move 4560, (2040 + i * 700), 4455, 495
    ctlCmd1.Visible = True

    So a button with name "ctlCmd0" has been created.
    Now I want that when anyone will press the button, it should open some other form. If I put normal Private Sub ctlCmd0_Click() event, then it does nothing.

    So how I can add the Click event to a dynamically created button like this?

    Thanks in advance.
     
    shahilroyhere, Apr 12, 2011 IP