Checkboxes and Option Groups

P

PC Datasheet

How can the label for a checkbox and the labels for the options in an option
group be addressed? When a checkbox gets the focus, Access draws a dotted
box around the label. When an option group gets the focus, Access draws a
dotted box around the label of the first option or the label of the option
previously selected. I would like to change the backcolor of these labels to
yellow as the controls get focus.

For textboxes and comboboxes I have a function with the following code:
Function HiLiteControl()
Screen.ActiveControl.Backcolor = "8454143"
End Function

And I put the following in the GotFocus event of all the textboxes and
comboboxes:
=HiLiteControl()

I would like to be able to do something similar for the label for a checkbox
and the labels for the options in an option group.

Thanks!

Steve
 
B

Br@dley

PC said:
How can the label for a checkbox and the labels for the options in an
option group be addressed? When a checkbox gets the focus, Access
draws a dotted box around the label. When an option group gets the
focus, Access draws a dotted box around the label of the first option
or the label of the option previously selected. I would like to
change the backcolor of these labels to yellow as the controls get
focus.
For textboxes and comboboxes I have a function with the following
code: Function HiLiteControl()
Screen.ActiveControl.Backcolor = "8454143"
End Function

And I put the following in the GotFocus event of all the textboxes and
comboboxes:
=HiLiteControl()

I would like to be able to do something similar for the label for a
checkbox and the labels for the options in an option group.

Thanks!

Steve

I'd pass the control name to your function on each control's OnFocus
event. If it's an option group or something just pass the label's name
instead of the control?

eg. (something like this....)

Private Function HiLiteControl(pMyControl as Control)
pMyControl.BackColor = "8454143"
End Function

Private Sub txtMyTextBox_OnFocus()
HiLiteControl Me![txtMyTextBox]
End Sub

Their's probably a dozen ways of achieving this.

Also, how are you resetting the color when the control looses the focus?
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
 
R

rkc

PC said:
How can the label for a checkbox and the labels for the options in an option
group be addressed? When a checkbox gets the focus, Access draws a dotted
box around the label. When an option group gets the focus, Access draws a
dotted box around the label of the first option or the label of the option
previously selected. I would like to change the backcolor of these labels to
yellow as the controls get focus.

For textboxes and comboboxes I have a function with the following code:
Function HiLiteControl()
Screen.ActiveControl.Backcolor = "8454143"
End Function

And I put the following in the GotFocus event of all the textboxes and
comboboxes:
=HiLiteControl()

I would like to be able to do something similar for the label for a checkbox
and the labels for the options in an option group.

With checkboxes you can use Screen.ActiveControl.Controls(0).
The attached label is a 'child' of the combobox.

With Option Groups it's not so easy because the active control is the
Frame the option buttons are contained by.

Using Screen.ActiveControl in the LostFocus event to reset the
background is a runtime error waiting to happen. Clicking outside
the current form is one way to increase the odds of throwing an error.

Take Br@dley's advice. Ditch Screen.ActiveControl and write a function
that takes a control as an argument.

I'll wave my fee.
 
P

PC Datasheet

Bradley,

Thanks for responding!

I'm looking for a way to do something like screen.ActiveLabel so I can put
the same expression (=HiLiteLabel()) in the GotFocus event code line for all
the checkboxes and option groups.

I use the same process in the LostFocus event to reset the color using
backcolor of 16777215.

Steve


Br@dley said:
PC said:
How can the label for a checkbox and the labels for the options in an
option group be addressed? When a checkbox gets the focus, Access
draws a dotted box around the label. When an option group gets the
focus, Access draws a dotted box around the label of the first option
or the label of the option previously selected. I would like to
change the backcolor of these labels to yellow as the controls get
focus.
For textboxes and comboboxes I have a function with the following
code: Function HiLiteControl()
Screen.ActiveControl.Backcolor = "8454143"
End Function

And I put the following in the GotFocus event of all the textboxes and
comboboxes:
=HiLiteControl()

I would like to be able to do something similar for the label for a
checkbox and the labels for the options in an option group.

Thanks!

Steve

I'd pass the control name to your function on each control's OnFocus
event. If it's an option group or something just pass the label's name
instead of the control?

eg. (something like this....)

Private Function HiLiteControl(pMyControl as Control)
pMyControl.BackColor = "8454143"
End Function

Private Sub txtMyTextBox_OnFocus()
HiLiteControl Me![txtMyTextBox]
End Sub

Their's probably a dozen ways of achieving this.

Also, how are you resetting the color when the control looses the focus?
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
 
P

PC Datasheet

Thanks for replying!

< Using Screen.ActiveControl in the LostFocus event to reset the background
is a runtime error waiting to happen. >
Why?

If I write a function that takes a control as an argument, I have to pass a
different control name at each call of the function. Is there a way to avoid
that. Screen.ActiveControl avoids that for textboxes and comboboxes and
that's why I use it. When I posted the question I was hoping to find
something like Screen.ActiveControl.Label.

Steve
 
P

PC Datasheet

I meant to previously ask ----

<With Option Groups it's not so easy ........>
Is it possible? How?

Thanks!

Steve
 
T

Thelma Lubkin

: PC Datasheet wrote:

<snip any substance>

: I'll wave my fee.

So it seems that you're not going to waive your fee -- otherwise
you'll have nothing to wave.

sorry, I couldn't resist such a good bad pun.
--thelma
 
J

John Marshall, MVP

Thelma Lubkin said:
: PC Datasheet wrote:

<snip any substance>

: I'll wave my fee.

So it seems that you're not going to waive your fee -- otherwise
you'll have nothing to wave.

sorry, I couldn't resist such a good bad pun.
--thelma


That's ok, PC always has a problem with spelling. He just does not have a
good dictionary.
(and forgets these newsgroups are for free help)

John... Visio MVP
 
P

PC Datasheet

Once again you demonstrate your intelligence! MVP must come in a crackerjack
box!

< I'll wave my fee.>
These were rkc's words not mine.

Is this why you have tried to reverse what you said 6 times in the last few
days.

Checkmate!

You lose.

BTW, did you ever look up metaphor?

Steve
 
M

Marshall Barton

If you know what form all this is happening in, you should
use formobject.ActiveControl instead of the Screen object.
The Screen object covers too much territory.

I'm not convinced that I know where the focus is during the
LostFocus event, you may want to explore using the Exit
event instead.

The last item clicked on in an option group has the
OptionValue that matches the frame's Value.

Since label controls can not receive the focus, there is no
such thing as an active label. This means that the only
thing that knows an unattached label was clicked on is the
label's Click event procedure.

Clicking on an attached label moves the focus to the control
the label is attached to, so the label never gets involved.
As rkc said, you can get to the attached label using the
ActiveControl's Controls collection. All the control in an
option group are in the frame's Controls collection.
 
P

PC Datasheet

Marsh,

Thanks for responding!

I'm trying to use the function across 7 forms so formobject won't work
unless there's a way to incorporate the ActiveForm property.

Your suggestion of using the Exit event sounds good!

Say an option group has three radio buttons and three associated labels. Are
the controls referenced Controls(0) to Controls(5)? And are they in the same
order as the options?

I know there's no such thing as Active.Label; I was just using that
expression as "pseudocode".

Steve


Marshall Barton said:
If you know what form all this is happening in, you should
use formobject.ActiveControl instead of the Screen object.
The Screen object covers too much territory.

I'm not convinced that I know where the focus is during the
LostFocus event, you may want to explore using the Exit
event instead.

The last item clicked on in an option group has the
OptionValue that matches the frame's Value.

Since label controls can not receive the focus, there is no
such thing as an active label. This means that the only
thing that knows an unattached label was clicked on is the
label's Click event procedure.

Clicking on an attached label moves the focus to the control
the label is attached to, so the label never gets involved.
As rkc said, you can get to the attached label using the
ActiveControl's Controls collection. All the control in an
option group are in the frame's Controls collection.
--
Marsh
MVP [MS Access]


PC said:
< Using Screen.ActiveControl in the LostFocus event to reset the
background
is a runtime error waiting to happen. >
Why?

If I write a function that takes a control as an argument, I have to pass
a
different control name at each call of the function. Is there a way to
avoid
that. Screen.ActiveControl avoids that for textboxes and comboboxes and
that's why I use it. When I posted the question I was hoping to find
something like Screen.ActiveControl.Label.


"rkc" wrote
 
B

Br@dley

PC said:
Thanks for replying!

< Using Screen.ActiveControl in the LostFocus event to reset the
background is a runtime error waiting to happen. >
Why?

If I write a function that takes a control as an argument, I have to
pass a different control name at each call of the function. Is there
a way to avoid that. Screen.ActiveControl avoids that for textboxes
and comboboxes and that's why I use it. When I posted the question I
was hoping to find something like Screen.ActiveControl.Label.

Steve

If you make an assumption that your label's name is the same as the
control's but perhaps with an "lbl" prefix, and you test to see the
current control type... you could then refence the label based on the
contorl name.


eg. Me!("lbl" & Me.ActiveControl.Name).BackColor = 1234

(Seems messy to me though)

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
 
R

rkc

Thelma said:
: PC Datasheet wrote:

<snip any substance>

: I'll wave my fee.

So it seems that you're not going to waive your fee -- otherwise
you'll have nothing to wave.

sorry, I couldn't resist such a good bad pun.
--thelma

I actually appreciate you pointing that out and am further happy
that you found substance to snip.
 
R

rkc

PC said:
I meant to previously ask ----

<With Option Groups it's not so easy ........>
Is it possible? How?

I'm sure it is. I just haven't woked it out yet because I
have never wanted to do it.

I think maybe Br@dley's suggestion of using naming conventions
might help. The problem I think you will run into is that the
Frame is the activecontrol even when one of it's contained
objects has the focus. I could be wrong.

I'll take a closer look after I finish trying to make a living
today. Hopefully you'll have a solution before then.
 
R

rkc

PC said:
Marsh,

Thanks for responding!

I'm trying to use the function across 7 forms so formobject won't work
unless there's a way to incorporate the ActiveForm property.

Your suggestion of using the Exit event sounds good!

Say an option group has three radio buttons and three associated labels. Are
the controls referenced Controls(0) to Controls(5)? And are they in the same
order as the options?

All the controls contained in a Frame are members of the Frame's
controls collection. When first created they are ordered by the
order they were created in. Label first followed by the option button
it is attached to. I do not know if that can't be counted on not to
change during runtime, further editing of the form or the planets
being aligned in a certain way.


I'll wave goodbye to my fee.
 
M

Marshall Barton

You may want to use a Sub in each form's module to supply
the form object argument to the standard module procedure.
Otherwise, trust the Screen object and forge ahead.

The order of items in a frame's (or any other object's)
Controls collection) is undocumented (except the frame's
attached label, if it exists, should always be index 0, so
you should not count on it. You can loop through the
collection comparing the control type and option value.
Once you locate the "active" radio button, then use that
control's Controls collection to reference the label. Have
a play with this scenario, using Debug to see what other
controls are in each control's Controls collection. OTOH,
the option group control doesn't even have the Got/Lost
Focus or Enter/Exit events, so I don't really understand the
issue with this aspect the question.

My point about there being no such thing as an "ActiveLabel"
is that the concept is flawed and thinking about it that way
will lead you astray. You need to think in terms of the
active control and highlighting its attached label, if it
has on--
Marsh
MVP [MS Access]
 
A

Arno R

PC Datasheet said:
I meant to previously ask ----

<With Option Groups it's not so easy ........>
Is it possible? How?

Thanks!

Steve

I did work out a very easy function to do just what you want.
The Function is called FormatOptionGroupLabels()
The function uses a naming-convention as Br@dley already suggested.

This is a generic function that uses Screen.ActiveForm.
You will need to use this function once after opening your form
(if you want the formatting for the chosen values at that time)
and/or you need to use the function on the AfterUpdate-event of your Option Groups.

If you are interested contact me and I will send you a screenshot.

Arno R
 
P

PC Datasheet

Thank you for responding!

I am interested. I would appreciate whatever you can send me.

Steve



PC Datasheet said:
I meant to previously ask ----

<With Option Groups it's not so easy ........>
Is it possible? How?

Thanks!

Steve

I did work out a very easy function to do just what you want.
The Function is called FormatOptionGroupLabels()
The function uses a naming-convention as Br@dley already suggested.

This is a generic function that uses Screen.ActiveForm.
You will need to use this function once after opening your form
(if you want the formatting for the chosen values at that time)
and/or you need to use the function on the AfterUpdate-event of your Option
Groups.

If you are interested contact me and I will send you a screenshot.

Arno R
 
A

Arno R

I just did send the screenshot to you.
As I said in the mail: If you stop your advertising you can have the code for free !

Arno R
 
A

Arno R

"Arno R" <[email protected]> schreef in bericht I just did send the screenshot to you.
As I said in the mail: If you stop your advertising you can have the code for free !

Arno R

Since I don't here from you again, I guess your are not interested in free code or free support?

Arno R
 

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