Variable Not Defined Error
I'm using this code straight from the box. Only thing is this is a MDI child.
VB Code:
Option Explicit
Dim WithEvents cmdButton As CommandButton
Private Sub cmdButton_Click()
MsgBox "hi"
End Sub
Private Sub Form_Load()
Set cmdButton = Me.Controls.Add("VB.CommandButton", "newCommandButton")
With cmbButton
.Left = 1000
.Top = 1000
.Width = 2000
.Height = 500
.Caption = "Hello"
.Visible = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set cmdButton = Nothing
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.
Re: Variable Not Defined Error
You didn't declare cmbButton.
You did declare cmdButton.
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 ;)
Re: Variable Not Defined Error
Jacob.... That didn't yeild any results either. What did I do wrong! Something simple I bet.
Re: Variable Not Defined Error
Look into Post #2. You spelt cmbButton wrong. It's suppose to be cmdButton.
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:
Dim WithEvents cmdButton As CommandButton