Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need CommandButton to have dule function - ie.: Do\Un-Do 2

Status
Not open for further replies.

Acquaman

Technical User
Feb 14, 2003
21
US
Hello, and thank you very much for takeing time to help me with this problem.

What I want to have in my application is a Command Button with more than one function. Specifically, I want to VOID a document and then be able to UN-VOID it with a second click of the same Command Button.

Can anyone help me? Again, thank you so much.
Acquaman
 

Change the caption from one to the other (say undo and redo) or you could use the tag property to keep track of it also.
[tt]
Private Sub Command1_Click()
If Command1.Text = "Undo" Then
Command1.Text = "Redo"
'do other stuff
Else
Command1.Text = "Undo"
' do other stuff
End If
End Sub
[/tt]

Good Luck

 
Or use a CheckBox set to Graphical style:

Private Sub Check1_Click()
If Check1.Value = vbChecked Then
Debug.Print "Voiding"
Else
Debug.Print "Unvoiding"
End If
End Sub
 
Might be an idea to avoid the tag property. I hear it's not supported in dot net, so when us ol' timers eventually wake up and sniff the cocoa...

mmilan
 
Hey, now that was service, 3 responses w\in 12 hrs!
Thank you so much for the code guys.
vb5prgrmr - I think because my control buttons originated from the control tool box and exist in a worksheet not a user form, that I was unable to get the button caption to change with your code. I do believe that I will go ahead with an if,then, else and just leave the caption "VOID". It will be quicker and I'm up against a deadline.

Thank you also strongm - I really appreciate your approach, as usuall. I look forward to the answers both of you give to the questions posted here at Tek-Tips.

I did work out another solution this morning with, for the most part satisfactory results. I placed the "VOID" button on top of an "UN-VOID" button and reduced the hight and width of the top button to zero once it is clicked. This reveals the "UN-VOID" button below. I reversed the change when the "UN-VOID" button is clicked. To the user it appears to be the same button with a changing caption.

Not sure I'll use my solution. Because of the number of buttons it will take a lot more time to do.

Thanks again.
Sincerely,
Acquaman
 
You can use vb5's code successfully if you just change .Text to .Caption

Here is one I tested in Excel (as you said worksheet):

Private Sub cmd1_Click()
With cmd1
If .Caption = "Void" Then
.Caption = "UnVoid"
Else
.Caption = "Void"
End If
End With
End Sub


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 

Where did I get Text from???? hurugmph ... Well I guess that is what you get without using an editor ...

Yeah just change my .Text to .Caption ...

Good Luck

 
Thank you johnwn and vb5.
Now I can get the desired result. Boy am I glad I did not go through with my solution of shrinking the "VOID" button.
You're the BEST!
Sincerely,
Acquaman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top