Search code examples
ms-accesstogglebutton

Toggling the Caption on a continuous Form


On a continuous form I am attempting to toggle the caption of a toggle button to match the button’s state. In this case when the record/state is True, I would like the button to read “Current” and if the record is False have the button read “Obsolete”.

enter image description here

The script below works in switching between the two desired values but is switches all of the visible buttons and not for the individual records. I am not sure how to tie the individual records to the individual togglebutton's caption.

Private Sub Toggle5_Click()
    If Me.Toggle5.Value = True Then
        Me.Toggle5.Caption = "Current"
      Else:
        Me.Toggle5.Caption = "Obsolete"
    End If
End Sub

I am using MS- Access 2013, I expect this question has been answer before, I have not found a working solution.


Solution

  • As Gustav wrote, you cannot do this directly. All static properties of controls in a continuous form always apply to all instances of that control.

    Possible workaround:

    Use a textbox (disabled & locked, perhaps with special effect = Raised) to show the text, with a control source like this:

    = IIf([Status]=True, "Current", "Obsolete")
    

    Put a transparent button on top of it, for easy clickability (it won't show a Click animation though).

    Use Conditional formatting to set the background color of the textbox.