PDA

View Full Version : Solved: Changing the Command Button Captain



EPamperin12
04-10-2008, 12:34 PM
I have a form that is used by multiple teams. I had 5 command buttons for different steps that this form goes through. I had originally thought that I would be able to stack the buttons on top of each other and then delete the button after it had been clicked. However when it was emailed the buttons get stacked in a different order. I devised a way around this by using 1 command button that has a variable assigned with it and when it is clicked it will be able to perform a different task, depending on what the variable is. Is there a way to change the Caption on the command button by using VBA?

Any assistance is most appreciated.



Dim b as Integer ' Module Variable
Private Sub CommandButton1_Click()
If b = 0 Then
b = b + 1
ElseIf b < 0 Or b >= 2 Then
MsgBox "You must Open the Original Document"
ActiveDocument.Close (RouteDocument)
End If

If b = 1 Then
Application.Run ("CSCompleted")
'Want the Caption to be Internal Set Up Completed
b = 2
ElseIf b = 2 Then
Application.Run ("InternalCompleted")
'Want Caption to be Extract
b = 3
ElseIf b = 3 Then
Application.Run ("Extract")
'Want Caption to be Send to QC
b = 4
ElseIf b = 4 Then
Application.Run ("SendtoQC")
'Want Caption to be QC Completed
b = 5
ElseIf b = 5 Then
Application.Run ("QCCompleted")
'Will Delete Command Button
b = 6
Else
End If
End Sub

fumei
04-10-2008, 12:41 PM
Controls like a commandbutton have a Caption property. So...change it.

If b = 1 Then
Application.Run ("CSCompleted")
CommandButton1.Caption = "Internal Set Up Completed"
b = 2
ElseIf b = 2 Then
Application.Run ("InternalCompleted")
CommandButton1.Caption = "Extract"
b = 3

EPamperin12
04-10-2008, 12:50 PM
Thank you I didn't realize it was that easy

fumei
04-11-2008, 09:50 AM
It is a VERY good idea to look in Help on things.

If you had typed "commandbutton" into Help, you would get Help on it. You could click on Properties, and easily see a Caption property. Or even just click on Example. The example has a .Caption text change.