Hope i've explained it ok
Thanks guys,
Jen
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.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200911/1
Using the AfterUpdate event of Status...
Private Sub Status_AfterUpdate()
If Status = True Then
lblStatus.ForeColor = QBColor(10)
lblStatus.Caption = "Active"
Else
lblStatus.ForeColor = QBColor(12)
lblStatus.Caption = "InActive"
End If
End Sub
That will change the label and label color whenever Status is changed.
**You'll also need that same code in the OnCurrent event of the form, so
that when you browse to a record, the Status label and forecolor will be
corrected for it's value.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html
"Find a job that you love... and you'll never work a day in your life."
"Jen" <J...@discussions.microsoft.com> wrote in message
news:3CE45938-8C55-423C...@microsoft.com...
Put this code in the option group Click event (change all occurrences of
opActiveInactive below to the name of your option group, and if necessary,
change the values of the active and inactive options).
Private Sub opActiveInactive_Click()
' If Active is chosen, turn that label green. If Inactive, turn that lavel
red
If Me.opActiveInactive.Value = 1 Then
Me.lblActive.ForeColor = vbGreen
Me.lblInactive.ForeColor = vbBlack
Else
Me.lblActive.ForeColor = vbBlack
Me.lblInactive.ForeColor = vbRed
End If
End Sub
You will also need to call this from the Load or Current form events so it
is set initially.
As for one radio button always selected, set the default to either Active or
Inactive, and that will take care of it.
--
Daryl S
The code needs to be in the Current event to assure correct label colors
every time the user navigates to a record. The Load event would affect only
the first record displayed.
AFAIK an option value needs to be numeric. The default value could be 1 to
show Active, but it cannot be set directly to "Active".
Daryl S wrote:
>Jen -
>
>Put this code in the option group Click event (change all occurrences of
>opActiveInactive below to the name of your option group, and if necessary,
>change the values of the active and inactive options).
>
>Private Sub opActiveInactive_Click()
>' If Active is chosen, turn that label green. If Inactive, turn that lavel
>red
>If Me.opActiveInactive.Value = 1 Then
> Me.lblActive.ForeColor = vbGreen
> Me.lblInactive.ForeColor = vbBlack
>Else
> Me.lblActive.ForeColor = vbBlack
> Me.lblInactive.ForeColor = vbRed
>End If
>End Sub
>
>You will also need to call this from the Load or Current form events so it
>is set initially.
>
>As for one radio button always selected, set the default to either Active or
>Inactive, and that will take care of it.
>
>> Hi again guys,
>> I've got a form which, among other controls, has two radio buttons
>[quoted text clipped - 10 lines]
>> Thanks guys,
>> Jen
--
Message posted via http://www.accessmonster.com
"Find a job that you love... and you'll never work a day in your life."
"Jen" <J...@discussions.microsoft.com> wrote in message
news:3CE45938-8C55-423C...@microsoft.com...
Thanks,
Jen
Open the form in design view. Click View >> Properties if the Property Sheet
is not already open. Click the Event tab. Click the three dots next to On
Current. It may open the code window directly, or you may need to click Code
Builder, OK. Seems to me this changed fairly recently. In any case, place
the code between Private Sub Form_Current() and End Sub.
Jen wrote:
>Hi Daryl,
> Thanks for your help....i've put the code in the Click event of the
>option group but i'm not sure what you mean by 'call from the Load or Current
>form events'. Does this mean i also must put the same code in the Load event
>of the form itself ? I'm no expert so sorry if this is a silly question
>
>Thanks,
>Jen
>
>> Jen -
>>
>[quoted text clipped - 34 lines]
The form's Load event only fires once... when the form is initially
opened.
You need your code to run every time you access a particular record. (so
the
correct forecolors are applied to the option group labels)
Therefore, you need to place the same "color" code as the AfterUpdate...
in
the form's OnCurrent event.
While there is no "rule", and there's nothing "wrong", with using a 2
check box
option group to represent a Boolean value, but just a simple check box, with
changing labels would be more appropriate.
Option groups, by their nature, are not Boolean, their purpose is to
return an
integer value. While a two check option group can be made to handle Boolean
logic, it is not really intended to do that.
Continue on with your option group solution... but consider my
suggestion for
your next Boolean field...
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html
"Find a job that you love... and you'll never work a day in your life."
"Jen" <J...@discussions.microsoft.com> wrote in message
news:0A86A74C-0583-49E4...@microsoft.com...
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:
***********
*****************
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
You guys are great.
Jen xoxo
Thanks,
Al Campagna
"BruceM" <Bru...@discussions.microsoft.com> wrote in message
news:77549365-4DEF-458C...@microsoft.com...