Change button caption on each click

S

Song

How to change button caption from "Check All" to "Check None" when
clicked, and change back when click again (toggle)? Because of space
limitation, I don't want to create 2 separate buttons.

When click Check All, I update the field to -1
When click Check None, I update the field to 0

Thanks
 
J

Jeanette Cunningham

Something like this in the button's click event.

With Me.cmdBtnName
If .Caption = "Check All" Then
.Caption = "Check None"
ElseIf .Caption = "Check None" Then
.Caption = "Check All"
End If
End With

Note: replace cmdBtnName with the name for your button.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
S

Song

Something like this in the button's click event.

With Me.cmdBtnName
    If .Caption = "Check All" Then
        .Caption = "Check None"
    ElseIf .Caption = "Check None" Then
        .Caption = "Check All"
    End If
End With

Note: replace cmdBtnName with the name for your button.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia








- Show quoted text -

Thank you, Jeanette. Under what event should I put the code? After
each click, I use docmd.runsql to replace all.
 
J

Jon Lewis

Or (assuming the field is Boolean):

Private Sub cmdBtnName_Click()
field = Not field
cmdBtnName.Caption = Switch(field, "Check None", Not field, "Check All")
End Sub

Jon
 
J

Jeanette Cunningham

As I mentioned in the last post, put the code in the on click event for the
button that runs that query.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Something like this in the button's click event.

With Me.cmdBtnName
If .Caption = "Check All" Then
.Caption = "Check None"
ElseIf .Caption = "Check None" Then
.Caption = "Check All"
End If
End With

Note: replace cmdBtnName with the name for your button.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia








- Show quoted text -

Thank you, Jeanette. Under what event should I put the code? After
each click, I use docmd.runsql to replace all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top