Toggle button

15 pts.
Tags:
cmdNew_Click event
Software development
Toggle buttons
I have two command buttons, CmdNew and CmdOld, where by clicking the first i make the second visible and vice versa for example Private Sub CmdNew_Click() Me!CmdOld.Visible = True End Sub I want to use only one toggle button instead,with two captions"Old" and "New". I have difficulties with making the buttons visible and invisible.Also.if i click New, the caption Old must appear and stay until i have clicked it.If i click Old, the caption Old must appear and stay until i click it. How could i do that ?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Instead of making two buttons, why not make one button that toggles its state? You can use the current caption to see what state it was in when it was clicked, and take the appropriate actions — including switching the caption. Eg:

<pre>Option Explicit

Const BTN_CAP_NEW As String = “New”
Const BTN_CAP_OLD As String = “Old”

Private Sub btn_Click()
If (btn.Caption = BTN_CAP_NEW) Then
‘ Actions if the “New” button was clicked
‘ …
btn.Caption = BTN_CAP_OLD
Else
‘ Actions if the “Old” button was clicked
‘ …
btn.Caption = BTN_CAP_NEW
End If
End Sub</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following