Full Version: Changing caption on control button
UtterAccess Forums > Microsoft Access > Access Forms
ctopham117
I have a control button that is controlled by a yes/no field. I would like this button to say one thing when in a True state and another when in a False state and have the action of pushing the button toggle the field.
theDBguy
Welcome to Utter Access!
If I understood your request correctly, in the Click event of the button, you could put something like:
Select Case Me.MyButton.Caption
Case "Yes"
Me.MyButton.Caption = "No"
Me.MyYesNoField = "Yes"
Case Else
Me.MyButton.Caption = "Yes"
My.MyYesNoField = "No"
End Select
Hope that helps...
ctopham117
Ok, thought I could figure it out, but I just don't understand the coding concept enough. I haven't figured out what is code and what is a user defined variable. I need the button to mark the control in my form/field in my table True when depressed and show the work "Completed" and if it isn't depressed (or was pushed again) to display "Not Completed". My control button is named Complete and the field/control are both named cmplted. I guessed the last "My" in the code was meant to be a "Me" since that was what the other was, but it still didn't run. I know I am changing a wrong part, but don't know which.
AQM_UK
I think you are right about the MY - typo from DBGuy there.
now see what you are doing. It depends how much room you have for this, but i like using an option group for this.
So this will show two values for Complete or Not Complete (I like WIP for work in progress)
So the user hit the completed button and the not complete will deselect. The value changes in the table.
This is easier as it requires no coding, and you can have many types of controls in the option group, buttons, radio buttons, checkboxes etc.
Jim
CyberCow
'`,,`,,`,
Hi ! and Welcome to Utter Access ! -o!
,`,,`,,`
CAn understanding of VBA will greatly empower your applications. If you want to get into it, try this link: Access VBA Tutorial. It's a free tutorial site for Access and VBA.
There are alos several excellent links to tutorials and such developed by the folks here at Utter Access . . .

hope this helps
AQM_UK
Hey Moo, you shaved?
imbo
CyberCow
Jimbo, yeah. Just didn't look right with the horns. wary.gif That and I have to be able to wear a respirator at work.
datAdrenaline
Why not just use a Check Box that is bound to your Yes/No field .... then no code needed ...
..
Otherwise ... to control the Caption based on a field value, then you can use a single line of code in the Forms "OnCurrent" event procedure ...
CODE
Me.<NameOfButton>.Caption = IIf(Me.<NameOfYesNoField>,"", "Not ") & "Completed"

Then ... the <NameOfButton> OnClick event procedure would look something like ...
CODE
Private Sub <NameOfButton>_Click()
    Me.<NameOfYesNoField> = Not Me.<NameOfYesNoField>
    Me.<NameOfButton>.Caption = IIf(Me.<NameOfYesNoField>,"", "Not ") & "Completed"
End Sub

{anything between and including the (<) and (>) are intended to represent user defined identifiers}
AQM_UK
I can understand that one. I got fed up of my Moustache when I has to wear snoods to go into flavour factories, so I thought "the time has come" and shaved it off.
im
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.