|
Prev: XML displays in console but not in text boxes
Next: Text box that holds more then 64K characters
From: HaydenT on 3 Jul 2008 03:21 '\\\\\\\\\\'MICROSOFT EXCEL 97 VISUAL BASIC EDITOR'////////// I am trying to create at runtime. I can create a control at runtime, but I can't get the control that was created at runtime to execute any code for example see below What I have done is: 'Create Userform and create a command button on the form. Put the following code in the newly 'created form. ' Dim myCmd As Control Dim myButton As Boolean Private Sub UserForm_Initialize() myButton = False End Sub Private Sub CommandButton1_Click() MsgBox "This Button was created at Run-time" End Sub Private Sub cmdCreate_Click() If myButton = True Then GoTo skip Set myCmd = frmRuntimeProblem.Controls.Add("Forms.CommandButton.1", , Visible) myCmd.Left = 102 myCmd.Top = 50 '186 myCmd.Width = 100 myCmd.Height = 24 myCmd.Caption = "Show Message" myButton = True MsgBox "myCmd.Name = " & myCmd.Name skip: End Sub
From: PeterD on 3 Jul 2008 10:50 On Thu, 3 Jul 2008 00:21:01 -0700, HaydenT <HaydenT(a)discussions.microsoft.com> wrote: >'\\\\\\\\\\'MICROSOFT EXCEL 97 VISUAL BASIC EDITOR'////////// > > >I am trying to create at runtime. I can create a control at runtime, but I >can't get the control that was created at >runtime to execute any code for example see below > >What I have done is: > >'Create Userform and create a command button on the form. Put the following >code in the newly >'created form. >' > >Dim myCmd As Control >Dim myButton As Boolean > >Private Sub UserForm_Initialize() > myButton = False >End Sub > >Private Sub CommandButton1_Click() ^^^^^^^^^^^^^^ > MsgBox "This Button was created at Run-time" >End Sub > >Private Sub cmdCreate_Click() > If myButton = True Then GoTo skip > Set myCmd = frmRuntimeProblem.Controls.Add("Forms.CommandButton.1", , ^^^^^^^^^^^^^^^ >Visible) > myCmd.Left = 102 > myCmd.Top = 50 '186 > myCmd.Width = 100 > myCmd.Height = 24 > myCmd.Caption = "Show Message" > myButton = True > MsgBox "myCmd.Name = " & myCmd.Name >skip: >End Sub You never create CommandButton1... (Look at your Controls.Add name). Also you call is wrong, you need to code it as: .... frmRuntimeProblem.Controls.Add(VB.CommandButton, CommandButton1) Your call doesn't give it a name, and as well, doesn't tell it properly what type of control to add. This is well documented in the VB help section.
From: PeterD on 3 Jul 2008 22:19 On Thu, 03 Jul 2008 10:50:31 -0400, PeterD <peter2(a)hipson.net> wrote: >On Thu, 3 Jul 2008 00:21:01 -0700, HaydenT ><HaydenT(a)discussions.microsoft.com> wrote: > >>'\\\\\\\\\\'MICROSOFT EXCEL 97 VISUAL BASIC EDITOR'////////// >> >> >>I am trying to create at runtime. I can create a control at runtime, but I >>can't get the control that was created at >>runtime to execute any code for example see below >> >>What I have done is: >> >>'Create Userform and create a command button on the form. Put the following >>code in the newly >>'created form. >>' >> >>Dim myCmd As Control >>Dim myButton As Boolean >> >>Private Sub UserForm_Initialize() >> myButton = False >>End Sub >> >>Private Sub CommandButton1_Click() > > ^^^^^^^^^^^^^^ > >> MsgBox "This Button was created at Run-time" >>End Sub >> >>Private Sub cmdCreate_Click() >> If myButton = True Then GoTo skip >> Set myCmd = frmRuntimeProblem.Controls.Add("Forms.CommandButton.1", , > > ^^^^^^^^^^^^^^^ > >>Visible) >> myCmd.Left = 102 >> myCmd.Top = 50 '186 >> myCmd.Width = 100 >> myCmd.Height = 24 >> myCmd.Caption = "Show Message" >> myButton = True >> MsgBox "myCmd.Name = " & myCmd.Name >>skip: >>End Sub > >You never create CommandButton1... (Look at your Controls.Add name). >Also you call is wrong, you need to code it as: > >... frmRuntimeProblem.Controls.Add(VB.CommandButton, CommandButton1) > >Your call doesn't give it a name, and as well, doesn't tell it >properly what type of control to add. > >This is well documented in the VB help section. Uh, with quotes around the name... (sorry)
|
Pages: 1 Prev: XML displays in console but not in text boxes Next: Text box that holds more then 64K characters |