|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to Call a button on a toolbar from other forms?Newbie vb6. Toolbar1 is located on Form1 and includes 3 buttons. A private sub on Form1 controls the function of these buttons such as this: Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Key Case "Button 1" Text1.Text="Button 1 is applied" End Select Case "Button 2" Text1.Text="Button 2 is applied" End Select Case "Reset" Text1.Text="Reset Button is applied" End Select End Sub Is it possible to call just the "Reset" button from another form (Form2)? How Can I do that? Thank you very much for any comments in advance. DORI Why do You let not call button Reset a public sub/functon like "Reset" that
You van call from anywhere in Your program? Yours friendly, Hans Heezemans Show quoteHide quote "DORI" <D***@discussions.microsoft.com> schreef in bericht news:CBF89975-17CB-47BD-B514-99694BBEFD5F@microsoft.com... > Dear All, > Newbie vb6. > Toolbar1 is located on Form1 and includes 3 buttons. A private sub on > Form1 > controls the function of these buttons such as this: > > Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) > Select Case Button.Key > Case "Button 1" > Text1.Text="Button 1 is applied" > End Select > Case "Button 2" > Text1.Text="Button 2 is applied" > End Select > Case "Reset" > Text1.Text="Reset Button is applied" > End Select > End Sub > > Is it possible to call just the "Reset" button from another form (Form2)? > How Can I do that? > Thank you very much for any comments in advance. > DORI
Show quote
Hide quote
"DORI" <D***@discussions.microsoft.com> wrote in message The code you posted won't run--too many 'End Select'snews:CBF89975-17CB-47BD-B514-99694BBEFD5F@microsoft.com... > Dear All, > Newbie vb6. > Toolbar1 is located on Form1 and includes 3 buttons. A private sub on Form1 > controls the function of these buttons such as this: > > Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) > Select Case Button.Key > Case "Button 1" > Text1.Text="Button 1 is applied" > End Select > Case "Button 2" > Text1.Text="Button 2 is applied" > End Select > Case "Reset" > Text1.Text="Reset Button is applied" > End Select > End Sub > > Is it possible to call just the "Reset" button from another form (Form2)? > How Can I do that? > Thank you very much for any comments in advance. > DORI It is usually best to copy & paste the code from your code module. At any rate, something like the code below may do what you want: 'Form1 Private Sub Form_Load() Form2.Show End Sub 'assuming the button Key values are the same as the Captions Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Key Case "Button 1" Text1.Text = "Button 1 is applied" Case "Button 2" Text1.Text = "Button 2 is applied" Case "Reset" Text1.Text = "Reset Button is applied" End Select End Sub 'Form2 Private Sub Command1_Click() With Form1 .Toolbar1.Buttons("Reset").Value = tbrPressed .Text1.Text = "Reset Button is applied" End With End Sub ============================================ Or--------- add this function to Form1 Public Sub Reset() 'public so it can be 'seen' from Form2 Dim Btn As MSComctlLib.Button Set Btn = Toolbar1.Buttons("Reset") Toolbar1_ButtonClick Btn End Sub And in Form2------ Private Sub Command1_Click() With Form1 .Reset End With End Sub Dear Norm Cook,
Thank you so much for the code. I learn something new every time I post a question on this forum. You are very helpful people. Thanks, DORI Show quoteHide quote "Norm Cook" wrote: > "DORI" <D***@discussions.microsoft.com> wrote in message > news:CBF89975-17CB-47BD-B514-99694BBEFD5F@microsoft.com... > > Dear All, > > Newbie vb6. > > Toolbar1 is located on Form1 and includes 3 buttons. A private sub on > Form1 > > controls the function of these buttons such as this: > > > > Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) > > Select Case Button.Key > > Case "Button 1" > > Text1.Text="Button 1 is applied" > > End Select > > Case "Button 2" > > Text1.Text="Button 2 is applied" > > End Select > > Case "Reset" > > Text1.Text="Reset Button is applied" > > End Select > > End Sub > > > > Is it possible to call just the "Reset" button from another form (Form2)? > > How Can I do that? > > Thank you very much for any comments in advance. > > DORI > > The code you posted won't run--too many 'End Select's > It is usually best to copy & paste the code from your code module. > At any rate, something like the code below may do what you want: > > 'Form1 > Private Sub Form_Load() > Form2.Show > End Sub > > 'assuming the button Key values are the same as the Captions > Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) > Select Case Button.Key > Case "Button 1" > Text1.Text = "Button 1 is applied" > Case "Button 2" > Text1.Text = "Button 2 is applied" > Case "Reset" > Text1.Text = "Reset Button is applied" > End Select > End Sub > > 'Form2 > Private Sub Command1_Click() > With Form1 > .Toolbar1.Buttons("Reset").Value = tbrPressed > .Text1.Text = "Reset Button is applied" > End With > End Sub > ============================================ > Or--------- > add this function to Form1 > Public Sub Reset() 'public so it can be 'seen' from Form2 > Dim Btn As MSComctlLib.Button > Set Btn = Toolbar1.Buttons("Reset") > Toolbar1_ButtonClick Btn > End Sub > And in Form2------ > Private Sub Command1_Click() > With Form1 > .Reset > End With > End Sub > > >
THANKS TO ALL
A much simpler question re subroutines QB coder (in 4K!) struggles with vb concept (groan). Microsoft Printer Compatibility Library 1.0 now available Mouse events to moved picturebox Setting focus to the Form Troubles with User Permission object required error Anyone using libcurl with VB / VBA? advanced recordset sorting |
|||||||||||||||||||||||