Results 1 to 7 of 7

Thread: add command button

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    8

    add command button

    How do i add a command buttun to the form?
    Private Sub Command1_Click()

    'Code to add the command buttun

    End Sub

  2. #2
    I believe it goes something like this:
    VB Code:
    1. Dim cmdSomeNewButton As New Command1
    2. Load cmdSomeNewButton
    3. cmdSomeNewButton.Caption = "I'm a new button"
    (PS, enclose your code in [vbcode][/vbcode] tags to have it automatically color coded. )

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    8
    Originally posted by filburt1
    I believe it goes something like this:
    VB Code:
    1. Dim
    2. Load cmdSomeNewButton
    3. cmdSomeNewButton.Caption = "I'm a new button"
    (PS, enclose your code in [vbcode][/vbcode] tags to have it automatically color coded. )
    Didn't work!
    User-Defined Type Not defined at cmdSomeNewButton As New Command1

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    try this...
    VB Code:
    1. Dim WithEvents cmdNewButton As CommandButton
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.   Set cmdNewButton = Me.Controls.Add("VB.CommandButton",cmd)
    6.  
    7.   With cmdNewButton
    8.     .Visible = True
    9.     .Top = 10
    10.     .Left = 10
    11.   End With
    12.  
    13. End Sub
    14.  
    15. Private Sub cmdNewButton_Click()
    16.   MsgBox "I'm a new button"
    17. End Sub
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    8
    still not working. the error is

    Run-time error '50132'
    Not a legal object name: "

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Set cmdNewButton = Me.Controls.Add("VB.CommandButton",cmd)

    just for sh*ts and giggles, try changing the above line to :

    Set cmdNewButton = Me.Controls.Add("VB.CommandButton","cmd")

    and see if it works.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    8
    VB Code:
    1. Set cmdNewButton = Me.Controls.Add("VB.CommandButton",cmd)
    2.  
    3. just for sh*ts and giggles, try changing the above line to :
    4.  
    5. Set cmdNewButton = Me.Controls.Add("VB.CommandButton","cmd")
    6.  
    7. and see if it works.
    Yes it worked.
    Thank You All

Posting Permissions

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



Click Here to Expand Forum to Full Width