Reputation: 2030
Is it possible to create a Toggle Button inside of an Access Form which has more than two "states"/Options?
I'm creating a calendar with a monthly view which is composed of Toggle Buttons. The user should be able to click the toggle buttons in order to indicate if he is:
I therefore need a Toggle Button capable of 3 or more states/options.
If you have any alternative ideas to a Toggle Button method I would be very grateful.
As an idea of what my calendar looks like with toggle buttons here is a picture of my form:
Upvotes: 2
Views: 8808
Reputation: 97131
I like Tom's approach with label controls for Access 2007. The procedure below made it easy to use each label's click event to toggle between green, yellow, and red.
Call the procedure like this for each of the labels.
Private Sub Label16_Click()
ToggleColor Me.Label16
End Sub
Private Sub ToggleColor(ByRef lbl As Label)
Dim lngColor As Long
Dim strPrompt As String
If lbl.BackStyle = 0 Then ' Transparent
strPrompt = "BackColor will not be displayed when " & _
"BackStyle is Transparent." & vbCrLf & _
"Change " & lbl.Name & " BackStyle property to Normal."
MsgBox strPrompt, vbExclamation
Else
Select Case lbl.BackColor
Case vbGreen
lngColor = vbYellow
Case vbYellow
lngColor = vbRed
Case vbRed
lngColor = vbGreen
Case Else
lngColor = vbGreen
End Select
lbl.BackColor = lngColor
End If
End Sub
Upvotes: 2
Reputation: 4069
Here's a sample of how to do it. You can modify it to accept a button reference to use the code for many buttons.
Also, it turns out this only works for Access 2010+. If using a version before 2010, you can use a label as a button instead.
Private Sub Btn_Click()
Select Case Me.Btn.BackColor
Case &HFF
Me.Btn.BackColor = &HFF00
Case &HFF00
Me.Btn.BackColor = &HFF0000
Case Else
Me.Btn.BackColor = &HFF
End Select
End Sub
This will cycle through the three possible states. I used different colors, but you can really use anything.
Upvotes: 2