Toggle Button Vsible/Invisible & Adding a Color Background for Eac

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use the following Event Procedure code (OnClick) to make a Label either
visible or invisible with a click of the toggle button:

Me![MyLabel].Visible = Not Me![MyLabel].Visible

But how can I add to this expression to provide me a color for each. For
example,

Me![MyLabel].Visible (with a green background) = Not Me![MyLabel].Visible
(with a grey background).

I know the colors are referenced with numbers, but all I need is the
expression.

Thanks
Tank
 
What is the point? Once it Visible = False, you will not see it, even if the
back sty;e is set to normal. But, so you can find out for yourself, you
would have to rewrite the code:

If Me.MyLabel.Visible = True Then
Me.MyLabel.BackColor = -2147483633 'Same as default Form Detail section
Me.MyLabel.Visible = True
Else
Me.MyLabel.BackColor = vbGreen
Me.MyLabel.Visible = False
End If
 
Thanks so much Klatuu. I was hoping it would be shorter in such a way that I
could simply include the background color on the single line. But your
expression allows me a clear understanding as to how to proceed.

For your information, I am using it in a rather unusual situation as a part
of a name and address grouping. The primary user wants to see and enter a
person's name on a line as LastName, Firstname, MiddleName (3 controls of
course). But I want to give other users the ability to enter the name in the
usual order: FirstName, Middlename, LastName.

So, I'm creating two separate lines (not one on top of the other so that I
can see them easier in design view). When the top line (showing LName,
FName, MName) is visible, the second line is invisible, but I want the space
between line 1 and line 3 to be other than my background color for the page
for the purpose of adding "visual continuity" among lines 1, 3, 4, 5, etc.,
that make up a full name/address grouping.
If I sue the backgorund color for line 2 when it is invisible, it makes line
1 look detached from lines 3, 4, 5, etc.

I can easily work with your expression, so you have graciously set me on the
right path, and I am grateful for your offering your skill along with such an
expendient reply.

Tank
 
How are you handling the fact that there will be two different controls for
each of LastName, FirstName, and MiddleName? That would get a little
complicated. I think you may want to consider changing the location of the
controls.
Basically, what you would need to do is move the controls into the positions
they need to be in for the order you want them in. It also involves changing
the captions in the 3 labels so you don't have to move them, and setting the
tab stop property of each so they will tab in the correct order. Now to do
all this without startling the user, you will want to turn Echo off before
you begin the moves and back on afterwards so they will see the changes.
Changing the location of a control is nothing more than setting the Left and
Top properties. Note these properties are in twips. There are 1440 twips
per inch. You can qet the values and know where to move them. I would
suggest an Option Group with two toggle buttons to select the order. So here
is an example (air code) of what would happen:

(Replace the ???? with the numbers you get by determining the location. You
can to that in the immediate window with the form open by
?Forms!FormName!LastName.Top, etc.

So, in the After Update event of the option group (I call it opgOrder) with
values 1 and 2,

Const conLeftTop As Integer = ????
Const conLeftLeft As Integer = ????
Const conMidTop As Integer = ????
Const conMidLef As Integer = ????
Const conRightTop As Integer = ????
Const conRightLef As Integer = ????

Application.Echo False
With Me
.LastName.Left = IIf(opgOder = 1, conLeftLeft, conRightLeft)
.LastName.Top = IIf(opgOrder = 1, conLeftTop, conRightTop)
.FirstName.Left = IIf(opgOrder = 1, conMidLeft, conLeftLeft)
.FirstName.Top = IIf(opgOrder = 1, conMidTop, conLeftTop)
.MiddleName.Left = IIf(opgOrder = 1, conRightLeft, conMidLeft)
.MiddleName.Top = IIf(opgOrder = 1, conRightTop, conMidTop)
.FirstLabel.Caption = IIf(opgOdder = 1, "Last", "First")
.SecondLabel.Caption = IIf(opgOrder = 1, "First", "Middle")
.ThirdLabel.Caption = IIf(opgOrder = 1, "Middle", "Last")
.LastName.TabIndex = IIf(opgOrder = 1, 1, 3)
.FirstName.TabIndex = IIf(opgOrder = 1, 2, 1)
.MiddleName.TabIndex = IIf(opgOrder = 1, 3, 2)
End With
Application.Echo True

The above is air code, so may need some fixing, but if I had your task to
do, this is how I would do it.
 
Thanks Klatuu,

Your guidance offers a whole new approach for me that looks good for my needs.
To answer your entry question, I handled the two different controls for each
of the three-part name (LastName, FirstName, MiddleName in that order), along
with labels, without any real difficulty or complications. It was "visual"
and easy for me to work with.

Line 1 has a box (rectangle) containing these three controls. It's this
rectangle that I want to appear with a white background when that line is
VISIBLE. The page (containing other controls, such as street, city, state,
zip, tel, fax, email, etc.) has a different background color (medium green).
These controls (other than Line 1) have a background color of light green.

Line 2 has a similar rectangle containing the other three controls, named
FName, MName, LName, in that order. The controls and the rectangle
surrounding them has a background color of LIGHT GREEN when VISIBLE. But
when the three controls on Line 2 become INVISIBLE (via the Toggle Button),
the rectangle itself remains VISIBLE but appears blank inside. I want that
background color then to be LIGHT GREEN to match the background color of the
remaining address controls (street, city, state, zip, etc.). I don't want
the background color of this Line 2 rectangle to appear DARK GREEN that would
match the background color of the page. This would result in Line 1 (VISIBLE
when Line 2 is INVISIBLE) with WHITE background appearing totally separated
from the rest of the address lines.

Of course, when Line 1 (LastName, FirstName, MiddleName) becomes INVISIBLE,
all controls, including the rectangle, are INVISIBLE and the page background
color of DARK GREEN appears in the rectangle's place. Lines 2, 3, 4, 5, etc.
appear in together in LIGHT GREEN, and the lines appear all together. Your
solution accomplishes this as well. Your approach, if I'm reading your
expression corectly, eliminates the need to use two lines, and I like that
idea.

Sorry for the long explanation. My concept is rather "visual" in laying out
two lines for the name controls and is easier for me to follow. I'll work on
your approach which opens the door wider. That's how we grow. Thanks for
your valuable input.
 
Back
Top