Help with code to hide/unhide text box and label?


Big Wes

Hello. Thank you for helping. I am trying to do something that is a
bit beyond my experience level, but I think I can handle it if I can
get some help with the code. I am not experienced enough to move the
boxes around, so I am using 2 cells that are linked to the same field
in my table and hiding based on a selection in a checkbox.

I have a form in Access 2007 with a check box (I know check boxes are
not the best, but it was all I could come up with that I know how to
handle), three text boxes, and 2 labels. The boxes and labels overlap
in design view. I am trying to set it up so that if the checkbox is
checked, it will show "Address1", "Address2", and "AtLabel1". If the
checkbox is unchecked, it will show "Address3" and "AtLabel2".

Note: Address1 and Address3 are linked to the same field in my
table. I am doing it this way so I can add a text box between 2
others if the box is checked, but keep the same format with everything
next to the previous box. Example, if "Yes", "Address1", "Address2",
"Label1", but if "No", "Address1", "Address3", "Label2"

Sidebar: If I do this, do I need to be concerned about tab order? In
other words, if the text box is hidden, with the tab still stop on
that text box?

Form Name: EmailForm
Text Boxes: Address1, Address2, Address3
Label: AtLabel1, AtLabel2

Thank you again for the help.

Allen Browne

A simple way to do this is to convert the label into a text box.

Right-click the label, and Change To | Text Box.
Set the Control Source of the new text box to:
=IIf([Chk1], "Address1", "Address3")
substituting the name of your check box for Chk1.

You may want to set these properties this new text box also:
tab stop no
locked yes
on click [event procedure]
You can then set the code so that if you click on this text box, it sets
focus to the appropriate text box. This makes it behave like a label.

Do the same for your other text boxes.

Big Wes

Thanks Allen. I tried this, but I have a few problems.

1. If I set the tab stop to no, it causes a problem when the box is
checked, because I want this to be a tab stop. Can I program the text
box to be a tab stop if checked and not a tab stop if unchecked?

2. I want to hide one of the text boxes if the the checkbox is
unchecked. Is this possible?

Thanks Again.

Allen Browne

The idea is to set the tab stop of the label to No.

You can use the AfterUpdate of your text box to set the TabStop of another
control if you wish. Alternatively, you could SetFocus in its LostFocus

=IIf([chk1], "Something", Null)

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