Home All Groups Group Topic Archive Search About

How to Call a button on a toolbar from other forms?

Author
17 Dec 2006 6:54 AM
DORI
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

Author
17 Dec 2006 10:17 AM
Hans
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
Author
17 Dec 2006 1:57 PM
Norm Cook
Show quote Hide quote
"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
Author
17 Dec 2006 7:04 PM
DORI
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
>
>
>