Results 1 to 6 of 6

Thread: Variable Not Defined Error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Variable Not Defined Error

    I'm using this code straight from the box. Only thing is this is a MDI child.

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents cmdButton As CommandButton
    4.  
    5. Private Sub cmdButton_Click()
    6.     MsgBox "hi"
    7. End Sub
    8.  
    9.  
    10. Private Sub Form_Load()
    11.      
    12.     Set cmdButton = Me.Controls.Add("VB.CommandButton", "newCommandButton")
    13.      
    14.     With cmbButton
    15.         .Left = 1000
    16.         .Top = 1000
    17.         .Width = 2000
    18.         .Height = 500
    19.         .Caption = "Hello"
    20.         .Visible = True
    21.     End With
    22.  
    23. End Sub
    24.  
    25. Private Sub Form_Unload(Cancel As Integer)
    26.     Set cmdButton = Nothing
    27. End Sub

    It is highlighting the Form Load Procedure. I see nothing wrong with this code. I've tried tinkering with it only to make it worse.. Any Help appreciated. I'm looking for a dynamic way to create toolbar items.

  2. #2
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Variable Not Defined Error

    You didn't declare cmbButton.
    You did declare cmdButton.

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Variable Not Defined Error

    The Form_Load() event is fired before the Form and all of the objects in it are even loaded! Use the Form_Activate() event instead. That is fired after the form and objects are loaded

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: Variable Not Defined Error

    Jacob.... That didn't yeild any results either. What did I do wrong! Something simple I bet.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Variable Not Defined Error

    Look into Post #2. You spelt cmbButton wrong. It's suppose to be cmdButton.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: Variable Not Defined Error

    Ahah! Don't ever copy paste and not carefully examine the code. The code was found on the forums and actually has a fault in it.

    Any reason why I cant get this line not to work with a MDI parent and a coolbar?

    VB Code:
    1. Dim WithEvents cmdButton As CommandButton

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