Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change field colour after selecting radio button 1

Status
Not open for further replies.

JoBee

Technical User
Nov 9, 2010
4
GB
I need to change the background colour of the spouse_forename field according to which radio button is selected. I thought I should be using the event proceedure after update in the group, but I have tried and failed to make this work. The following code is producing run time error 2427

Private Sub Frame349_AfterUpdate()

If Me.Option352.Value = 1 Then
Spouse_Forename.BackColor = vbRed

ElseIf Me.Option354.Value = 2 Then
Spouse_Forename.BackColor = vbWhite
End If

End Sub

Have also tried:

Private Sub Frame349_AfterUpdate()

If Me.Option352.Value = 1 Then
Me.Spouse_Forename.BackColor = vbRed

ElseIf Me.Option354.Value = 2 Then
Me.Spouse_Forename.BackColor = vbWhite
End If

End Sub


Not very technical, only have a very basic understanding, so any help would be appreciated.
 
You don't test an option group for each option - you test the FRAME which is the GROUP.

Code:
Select Case Me.MyOptionGroup
   Case 1
       Spouse_Forename.BackColor = vbRed
   Case 2
       Spouse_Forename.BackColor = vbWhite
End Select



Bob Larson
Free Access Tutorials and Samples:
 
Thanks for this, fixed in the blink of an eye. I have been messing about with this for 3 hours.

Thanks again.
 
Spoke too soon, if I select single applicant radio button it colours the spouse_forename field red in all records, regardless of the selection within those records.

What am I doing wrong?
 
That sounds like you are trying to use this on a continuous form, which you can't. You would need to use conditional formatting instead of code to do it.

You would select the Spouse_Forename control and go to FORMAT > CONDITIONAL FORMATTING (if in 2003 or below) and right click on the control in 2007 or above to select CONDITIONAL FORMATTING.

Then you would change the FIELD VALUE IS to EXPRESSION IS and put in
[YourOptionGroupName]=1

and set the format to red backcolor (look for the tipping paint bucket).

Then add another condition and put
[YourOptionGroupNameHere] = 2

and select the format you want when it is this.

Bob Larson
Free Access Tutorials and Samples:
 
I forgot to mention that you will need to have a field to store the option group value in the same table that your form is based on. Otherwise it will just color them all as well.

Bob Larson
Free Access Tutorials and Samples:
 
That worked. Thanks for your help. [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top