Jen,
There have been a number of replies in this thread that are not showing up
here. I used AccessMonster, and Al Campagna made some replies too. If you
are using the Microsoft web interface you are not getting all of the
conversation. The web interface has often had problems, and it seems
unlikely it will ever be reliable. Maybe the problem is somewhere other than
the Microsoft web page, but I doubt it. You should use a different news
reader. For web interfaces AccessMonster is not too bad, but best would be a
newsreader. Most e-mail programs can be used as newsreaders, or you can use
a dedicated newsreader program.
In any case, the Click event will fire when you click anywhere within the
option group that is not already occupied by another control. The best event
to use is After Update.
Also, the Load event will apply only to the first record you see upon
loading the form. The formatting applied then will remain until the next
time you update the option group (or click it, if you decide to go that way).
It will not change when you move to another record. To do that you need to
use the form's Current event.
You can call the option group After Update event in the form's Current event
or vice versa, but since either event could have code beyond what applies to
formatting, you may do better to create your own function. In the VBA editor
click Insert >> Procedure. Choose Function and Private, and give it a name
such as ControlColor. You can make the function Public, but if it is to be
used only for the one form there is no need to do that.
Insert the formatting code between Private Function ControlColor() and End
Function. In the form's Current event or the option group After Update event:
Call ControlColor
Here is the reply I posted last week:
***********
This is where an Option Group comes into play. Create an option group using
the toolbox. Add option buttons inside the option group box. You may need
to create new ones, as I think option buttons created outside an option group
have different properties than ones created inside the option group. Assign
each button an Option Value. Use 1 and 2. It doesn't matter which is which,
but for this discussion active is 1 and Inactive is 2.
Bind the option group to a number field ActiveStatus. You can set the
default value of the option group to 0, which should leave you with white
buttons rather than gray until one of the choices is selected. Or set the
Default Value to 1 to mark the Active button by default for a new record.
You no longer have an Active field and an Inactive field, but a single
ActiveStatus field that will be 1 for Active and 0 for Inactive. Remember,
the Option Group is bound to the field. The buttons are not bound to any
field.
I will call the Option Group grpActive, and the Labels lblActive and
lblInactive. In the After Update event of grpActive:
If Me.grpActive = 1 Then
Me.lblActive.BackColor = vbGreen
Me.lblInactive.BackColor = vbWhite
ElseIf Me.grpActive = 2 Then
Me.lblActive.BackColor = vbWhite
Me.lblInactive.BackColor = vbRed
Else
Me.lblActive.BackColor = vbGreen
Me.lblInactive.BackColor = vbWhite
End If
You could also use Select Case
Select Case Me.grpActive
Case 1
Me.lblActive.BackColor = vbGreen
Me.lblInactive.BackColor = vbWhite
Case 2
Me.lblActive.BackColor = vbWhite
Me.lblInactive.BackColor = vbRed
Case Else
Me.lblActive.BackColor = vbWhite
Me.lblInactive.BackColor = vbWhite
End If
You can simplify the expression if there are just two options:
If Me.grpActive = 1 Then
Me.lblActive.BackColor = vbGreen
Me.lblInactive.BackColor = vbWhite
Else
Me.lblActive.BackColor = vbWhite
Me.lblInactive.BackColor = vbRed
End If
You will need the same code in the form's Current event so the labels display
correctly when you arrive at an existing record.
*****************
Al suggested that for Active or Inactive there are just two choices, so a
single check box may be preferable to an Option Group. It would certainly be
simpler.
You can see the full discusssion at
www.accessmonster.com