A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Radio Button Problem



 
 
Thread Tools Display Modes
  #1  
Old November 6th, 2009, 12:36 PM posted to microsoft.public.access.forms
Jen
external usenet poster
 
Posts: 544
Default Radio Button Problem

Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not. My
problem is that when i click in the 'Active' control, i'd like the label to
turn green and when i click in the 'Inactive' control, i'd like that label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this possible
??

Hope i've explained it ok

Thanks guys,
Jen

  #2  
Old November 6th, 2009, 01:04 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Radio Button Problem

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.

Jen wrote:
Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not. My
problem is that when i click in the 'Active' control, i'd like the label to
turn green and when i click in the 'Inactive' control, i'd like that label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this possible
??

Hope i've explained it ok

Thanks guys,
Jen


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200911/1

  #3  
Old November 6th, 2009, 01:38 PM posted to microsoft.public.access.forms
Al Campagna[_2_]
external usenet poster
 
Posts: 1,462
Default Radio Button Problem

Jen
Sounds like your Active/Inactive logic should be Boolean (True/False)
Two individual, or two "Option Grouped" radio buttons are unnecessary.
Ex. A field in your table named Status (Boolean True/False)
One check box (or radio button) on the form will be able to indicate
both conditions. This presents a cleaner interface, and reduces coding
needed.
Ex, True display...
Status: O Inactive
or
Ex. False display...
Status: X Active

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" wrote in message
...
Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not.
My
problem is that when i click in the 'Active' control, i'd like the label
to
turn green and when i click in the 'Inactive' control, i'd like that label
to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this
possible
??

Hope i've explained it ok

Thanks guys,
Jen



  #4  
Old November 6th, 2009, 02:19 PM posted to microsoft.public.access.forms
Daryl S[_2_]
external usenet poster
 
Posts: 881
Default Radio Button Problem

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.

--
Daryl S


"Jen" wrote:

Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not. My
problem is that when i click in the 'Active' control, i'd like the label to
turn green and when i click in the 'Inactive' control, i'd like that label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this possible
??

Hope i've explained it ok

Thanks guys,
Jen

  #5  
Old November 6th, 2009, 04:26 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Radio Button Problem

I think the OP had free-standing option buttons, not an option group. In any
case, this seems to be essentially what I suggested. However, I would not
use the Click event, as it would run every time somebody clicks anywhere in
the option group. The After Update event is preferable, as it runs only when
the option group is updated.

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

  #6  
Old November 7th, 2009, 12:23 AM posted to microsoft.public.access.forms
Al Campagna[_2_]
external usenet poster
 
Posts: 1,462
Default Radio Button Problem

Jen,
A typo... My post should have read...
Ex. False display...
Status: O Inactive
or
Ex. True display...
Status: X Active
--
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" wrote in message
...
Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not.
My
problem is that when i click in the 'Active' control, i'd like the label
to
turn green and when i click in the 'Inactive' control, i'd like that label
to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this
possible
??

Hope i've explained it ok

Thanks guys,
Jen



  #7  
Old November 9th, 2009, 12:55 PM posted to microsoft.public.access.forms
Jen
external usenet poster
 
Posts: 544
Default Radio Button Problem

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

"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.

--
Daryl S


"Jen" wrote:

Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not. My
problem is that when i click in the 'Active' control, i'd like the label to
turn green and when i click in the 'Inactive' control, i'd like that label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this possible
??

Hope i've explained it ok

Thanks guys,
Jen

  #8  
Old November 9th, 2009, 02:27 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Radio Button Problem

It should be in the After Update event, not the Click event, and it should be
in the form's Current event. The Load event will not work. Reasons are
described in my previous posting.

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]
Thanks guys,
Jen


--
Message posted via http://www.accessmonster.com

  #9  
Old November 9th, 2009, 03:01 PM posted to microsoft.public.access.forms
Al Campagna[_2_]
external usenet poster
 
Posts: 1,462
Default Radio Button Problem

Jen,
First, a minor point...
The Click event of an option group fires every time
you click within the area of the option group, not just when changing
(updating)
the value. The more appropriate event would be the AfterUpdate event of the
option box. It only fires when the option group value changes.
Not a serious issue, but it should be mentioned.

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" wrote in message
...
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

"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.

--
Daryl S


"Jen" wrote:

Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates
to
whether a member of staff is currently working on a particular job or
not. My
problem is that when i click in the 'Active' control, i'd like the
label to
turn green and when i click in the 'Inactive' control, i'd like that
label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this
possible
??

Hope i've explained it ok

Thanks guys,
Jen



  #10  
Old November 9th, 2009, 03:54 PM posted to microsoft.public.access.forms
Brucem
external usenet poster
 
Posts: 10
Default Radio Button Problem

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


"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

"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.

--
Daryl S


"Jen" wrote:

Hi again guys,
I've got a form which, among other controls, has two radio buttons
beside each other with the labels 'Active' and 'Inactive'. This relates to
whether a member of staff is currently working on a particular job or not. My
problem is that when i click in the 'Active' control, i'd like the label to
turn green and when i click in the 'Inactive' control, i'd like that label to
turn red and the other label to revert back to plain white.
I'd also only like one 'dot' to be visible at all times. Is this possible
??

Hope i've explained it ok

Thanks guys,
Jen

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.