Share via

change color of toggle button

Anonymous
2013-06-16T03:12:52+00:00

I have a button on a form that filters records. The filtering is working great. 

I want the button to change colors when it's clicked to filter the records.

And when the user clicks the button again, the button needs to return to its normal color and the filter removed.

Is this possible?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2013-06-16T23:55:45+00:00

    I can see a backcolor property for the buttons I have on the form.

    At any rate, when I posed the question, I didn't realize that access had a toggle command button that can be added to the form with a wizard.

    So I ran the wizard to generate the button and added the code below to the on click event of the button.

    This is working great!

    Now the problem is that an access command button looks different than a toggle button. The toggle button has beveled edges, etc whereas a command button doesn't.

    I have all the buttons on the form placed vertically on the left side like a menu. All the buttons look uniform, except the toggle. I'd like all the buttons to look the same, except when the toggle button is in the down position. The code below takes care of the toggling back and forth.

    Is there a way to make the toggle button look like a command button so they all look the same unless the toggle is clicked?

    Here's the code:

    Private Sub Toggle397_Click()

    Dim strKeyword As String

    If Me.Toggle397 Then

    strKeyword = InputBox("Enter Search Terms", "Search in keywords")

    If strKeyword <> "" Then

    Me.Filter = "SampleNumber & "" "" & State & "" "" & County & "" "" & Date & "" "" & GeographicalName & "" "" & CollectionMethod & "" "" & Collector & "" "" & NPSUnit " & _

    "Like ""*" & strKeyword & "*"""

    Me.FilterOn = True

    Toggle397.Caption = "Turn Off Filter"

    End If

    Else

    Me.Filter = ""

    End If

    Me.FilterOn = Me.Toggle397

    End Sub

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-06-16T21:12:46+00:00

    Buttons, check boxes, radio and toggle buttons don't have the BackColor property so they can't do that.

    An alternative that might(?) be acceptable would be to use a text box control with some VBA code in its Click event procedure to toggle the value:

       Me.textboxname = Not Me.textboxname 

    and use Conditional Formatting to affect the back color.

    A different approach that I have used is to place a locked and disabled text box behind your button, but make it a little larger so it looks like a picture frame around the button.  Then use CF to affect the text box's color.

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2013-06-17T19:26:26+00:00

    I missed the new Backcolor property in A2010 (or was it A2007, which I never used).  Thanks for pointing it out.

    Unfortunately, they don't seem to have added the SpecialEffect property to either kind of button so you may have a few more options with these prebuilt buttons, but not enough to do what you want.  To be fair, MS is trying to maintain the "windows standard" for the "look and feel" across all applications where buttons that have different behaviors are supposed to look different.

    0 comments No comments