Option Group & Text Color Changes

  • Thread starter cmitchel via AccessMonster.com
  • Start date
C

cmitchel via AccessMonster.com

Good Morning.

I recently made a form that has an option group with 4 toggle buttons.
I coded the following on the option group (before update / after update &
Form Current) to change the color of the text on the button to red once
selected. This works great with one exception.. If I pull up an existing
record then click the New Record button the option group text color change
does not reset and carries over the last chosen text button (stays red)..

Private Sub StatusFrame1_BeforeUpdate(Cancel As Integer)
If Me.StatusFrame1.Value = 1 Then
Me.Toggle31.ForeColor = 255 'red
Me.Toggle31.FontWeight = 400 'normal
Me.Toggle32.ForeColor = 0 'black
Me.Toggle32.FontWeight = 400 'normal
Me.Toggle33.ForeColor = 0 'black
Me.Toggle33.FontWeight = 400 'normal
Me.Toggle34.ForeColor = 0 'black
Me.Toggle34.FontWeight = 400 'normal
End If
If Me.StatusFrame1.Value = 2 Then
Me.Toggle31.ForeColor = 0 'black
Me.Toggle31.FontWeight = 400 'normal
Me.Toggle32.ForeColor = 255 'red
Me.Toggle32.FontWeight = 400 'normal
Me.Toggle33.ForeColor = 0 'black
Me.Toggle33.FontWeight = 400 'normal
Me.Toggle34.ForeColor = 0 'black
Me.Toggle34.FontWeight = 400 'normal
End If
If Me.StatusFrame1.Value = 3 Then
Me.Toggle31.ForeColor = 0 'black
Me.Toggle31.FontWeight = 400 'normal
Me.Toggle32.ForeColor = 0 'black
Me.Toggle32.FontWeight = 400 'normal
Me.Toggle33.ForeColor = 255 'red
Me.Toggle33.FontWeight = 400 'normal
Me.Toggle34.ForeColor = 0 'black
Me.Toggle34.FontWeight = 400 'normal
End If
If Me.StatusFrame1.Value = 4 Then
Me.Toggle31.ForeColor = 0 'black
Me.Toggle31.FontWeight = 400 'normal
Me.Toggle32.ForeColor = 0 'black
Me.Toggle32.FontWeight = 400 'normal
Me.Toggle33.ForeColor = 0 'black
Me.Toggle33.FontWeight = 400 'normal
Me.Toggle34.ForeColor = 255 'red
Me.Toggle34.FontWeight = 400 'normal
End If
End Sub

same for After Update... & Form_Current

I have attempted to add the following to the code with no success:

If Me.StatusFrame1.Value = -1 Then <---- or should it be Null??
Me.Toggle31.ForeColor = 0 'black
Me.Toggle31.FontWeight = 400 'normal
Me.Toggle32.ForeColor = 0 'black
Me.Toggle32.FontWeight = 400 'normal
Me.Toggle33.ForeColor = 0 'black
Me.Toggle33.FontWeight = 400 'normal
Me.Toggle34.ForeColor = 0 'black
Me.Toggle34.FontWeight = 400 'normal
End If

Is there another way to do this? Do I have the correct coding, in the correct
places? Any assistance would be greatly appreciated! Make it a great day!!!
 
G

Guest

I assume the New Record button is one of the four. The code looks like it
should work, so there is something else happening.
You are checking the value of the option group. That value is based on the
Option Value property of the currently selected button. You are checking for
value 1 through 4. Check the Option Value property of the New Record button
first to see what it is. Then be sure the option values align correctly with
the names you are using in your code.

It should be in the After Update event. The Before update is too soon.

A couple of suggestions. You don't need to use the Value property. It is
the default value of the control. This would be a good place to use a Select
statement. If you use indenting, it makes your code much easier to read.
Here is the way I would write it:

Private Sub StatusFrame1_AfterUpdate(Cancel As Integer)
With Me
Select Case Me.StatusFrame1
Case 1
.Toggle31.ForeColor = 255 'red
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 2
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 255 'red
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 3
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 255 'red
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 4
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 255 'red
.Toggle34.FontWeight = 400 'normal
End Select
End With
End Sub

Now, just for grins, I am going to show you a way to do this with a lot less
code.

Private Sub StatusFrame1_AfterUpdate(Cancel As Integer)
Dim varColor As Variant
Dim varWeight As Variant
Dim lngSelected as Long

varColor = Array(0, 0, 0, 0)
varWeight = Array(400, 400, 400, 400)

With Me
lngSelected = .StatusFrame1 - 1
varColor(lngSelected) = 255
varWeight(lngSelected) = 400

.Toggle31.ForeColor = varColor(0)
.Toggle31.FontWeight = varWeight(0)
.Toggle32.ForeColor = varColor(1)
.Toggle32.FontWeight = varWeight(1)
.Toggle33.ForeColor = varColor(2)
.Toggle33.FontWeight = varWeight(3)
.Toggle34.ForeColor = varColor(3)
.Toggle34.FontWeight = varWeight(3)
End With
End Sub
 
C

cmitchel via AccessMonster.com

Excellent Thanks so much for responding! I will give it a try tonight.
I assume the New Record button is one of the four. The code looks like it
should work, so there is something else happening.
You are checking the value of the option group. That value is based on the
Option Value property of the currently selected button. You are checking for
value 1 through 4. Check the Option Value property of the New Record button
first to see what it is. Then be sure the option values align correctly with
the names you are using in your code.

It should be in the After Update event. The Before update is too soon.

A couple of suggestions. You don't need to use the Value property. It is
the default value of the control. This would be a good place to use a Select
statement. If you use indenting, it makes your code much easier to read.
Here is the way I would write it:

Private Sub StatusFrame1_AfterUpdate(Cancel As Integer)
With Me
Select Case Me.StatusFrame1
Case 1
.Toggle31.ForeColor = 255 'red
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 2
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 255 'red
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 3
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 255 'red
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 0 'black
.Toggle34.FontWeight = 400 'normal
Case 4
.Toggle31.ForeColor = 0 'black
.Toggle31.FontWeight = 400 'normal
.Toggle32.ForeColor = 0 'black
.Toggle32.FontWeight = 400 'normal
.Toggle33.ForeColor = 0 'black
.Toggle33.FontWeight = 400 'normal
.Toggle34.ForeColor = 255 'red
.Toggle34.FontWeight = 400 'normal
End Select
End With
End Sub

Now, just for grins, I am going to show you a way to do this with a lot less
code.

Private Sub StatusFrame1_AfterUpdate(Cancel As Integer)
Dim varColor As Variant
Dim varWeight As Variant
Dim lngSelected as Long

varColor = Array(0, 0, 0, 0)
varWeight = Array(400, 400, 400, 400)

With Me
lngSelected = .StatusFrame1 - 1
varColor(lngSelected) = 255
varWeight(lngSelected) = 400

.Toggle31.ForeColor = varColor(0)
.Toggle31.FontWeight = varWeight(0)
.Toggle32.ForeColor = varColor(1)
.Toggle32.FontWeight = varWeight(1)
.Toggle33.ForeColor = varColor(2)
.Toggle33.FontWeight = varWeight(3)
.Toggle34.ForeColor = varColor(3)
.Toggle34.FontWeight = varWeight(3)
End With
End Sub
Good Morning.
[quoted text clipped - 65 lines]
Is there another way to do this? Do I have the correct coding, in the correct
places? Any assistance would be greatly appreciated! Make it a great day!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top