Conditional Text Box Display

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

Guest

I have a text box in a form and I would only like it to display data if a
seperate field in the table is True. Is this something that can be done?

Example.

Tbl_PIP_Items.[Required Product Reference] is loaded in a form. I only want
it to display when Tbl_Hotels.[Brand] = "RD". Can this be done?
 
Use the form's Current Event. You posted field names, but those wont help.
You need to use the form's control names. Making up "guess " names, it would
be something like:

Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"
 
I tried that and they did not display. Do I have to set the visible field to
Yes?

Klatuu said:
Use the form's Current Event. You posted field names, but those wont help.
You need to use the form's control names. Making up "guess " names, it would
be something like:

Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"

--
Dave Hargis, Microsoft Access MVP


Chris said:
I have a text box in a form and I would only like it to display data if a
seperate field in the table is True. Is this something that can be done?

Example.

Tbl_PIP_Items.[Required Product Reference] is loaded in a form. I only want
it to display when Tbl_Hotels.[Brand] = "RD". Can this be done?
 
If you mean the Visible property of the text box, it doesn't really matter,
because you are changing it on each record.
Since I don't know what your control names really are, I made some up, but
the code I posted should work. Did you put it in the Current event of the
form?

One thing I did leave out, is how to handle new records. As is, it would
display the control for new records.

One other thing is how you worded your original post. You first said:
"I have a text box in a form and I would only like it to display data if a
seperate field in the table is True"

This would indicate a Boolean(Yes/No) data type field.

Then you said:
"I only want it to display when Tbl_Hotels.[Brand] = "RD""

Now we are talking about a text field. I did write the code for the text
field. Remember, when you are working in a form, you don't use the table's
field names. You use the form's control names. If you use the form wizard or
drag the fields off the field list onto the form, Access gives the control
the same name as the field. This is bad. Not only can it confuse us humans,
Access can sometimes get it wrong. So be sure your naming is good and you
are using the form control names.

Now here is the explanation:

This part:
Me.txtBrand = "RD"
will return True if the control is equal to "RD" and False if it is not

This part:
Me.txtRequiredProductReference.Visible =
Will set the Visible property of the control based on what is on the right
of the = sign.

So if you say:
Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"
it will evaluate the expression on the right side of the first = and return
either True or False, thus setting the Visible property.

We put it in the form's Current event because it fires every time the
current record changes. This includes when you open the form.

Sorry, but I know that works, it is a matter of getting the naming correct
and looking for the proper value.
--
Dave Hargis, Microsoft Access MVP


Chris said:
I tried that and they did not display. Do I have to set the visible field to
Yes?

Klatuu said:
Use the form's Current Event. You posted field names, but those wont help.
You need to use the form's control names. Making up "guess " names, it would
be something like:

Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"

--
Dave Hargis, Microsoft Access MVP


Chris said:
I have a text box in a form and I would only like it to display data if a
seperate field in the table is True. Is this something that can be done?

Example.

Tbl_PIP_Items.[Required Product Reference] is loaded in a form. I only want
it to display when Tbl_Hotels.[Brand] = "RD". Can this be done?
 
As i'm sure you can tell, I'm an Access novice. Where is the Current event
located?

Klatuu said:
If you mean the Visible property of the text box, it doesn't really matter,
because you are changing it on each record.
Since I don't know what your control names really are, I made some up, but
the code I posted should work. Did you put it in the Current event of the
form?

One thing I did leave out, is how to handle new records. As is, it would
display the control for new records.

One other thing is how you worded your original post. You first said:
"I have a text box in a form and I would only like it to display data if a
seperate field in the table is True"

This would indicate a Boolean(Yes/No) data type field.

Then you said:
"I only want it to display when Tbl_Hotels.[Brand] = "RD""

Now we are talking about a text field. I did write the code for the text
field. Remember, when you are working in a form, you don't use the table's
field names. You use the form's control names. If you use the form wizard or
drag the fields off the field list onto the form, Access gives the control
the same name as the field. This is bad. Not only can it confuse us humans,
Access can sometimes get it wrong. So be sure your naming is good and you
are using the form control names.

Now here is the explanation:

This part:
Me.txtBrand = "RD"
will return True if the control is equal to "RD" and False if it is not

This part:
Me.txtRequiredProductReference.Visible =
Will set the Visible property of the control based on what is on the right
of the = sign.

So if you say:
Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"
it will evaluate the expression on the right side of the first = and return
either True or False, thus setting the Visible property.

We put it in the form's Current event because it fires every time the
current record changes. This includes when you open the form.

Sorry, but I know that works, it is a matter of getting the naming correct
and looking for the proper value.
--
Dave Hargis, Microsoft Access MVP


Chris said:
I tried that and they did not display. Do I have to set the visible field to
Yes?

Klatuu said:
Use the form's Current Event. You posted field names, but those wont help.
You need to use the form's control names. Making up "guess " names, it would
be something like:

Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"

--
Dave Hargis, Microsoft Access MVP


:

I have a text box in a form and I would only like it to display data if a
seperate field in the table is True. Is this something that can be done?

Example.

Tbl_PIP_Items.[Required Product Reference] is loaded in a form. I only want
it to display when Tbl_Hotels.[Brand] = "RD". Can this be done?
 
Open your form in design mode
Open the Properties dialog box for the form
Select the Events tab
Click on the small button with 3 dots next to the Current event
Select Code Builder from the prompt
The VBA editor will open with the cursor positioned in the event.
Enter the code I posted, but change the names to those of your controls.
Save the code
Go back to the Access window and open the form and see what happens
(don't forget your saftey goggles, asbestos gloves, and steel toed boots)
--
Dave Hargis, Microsoft Access MVP


Chris said:
As i'm sure you can tell, I'm an Access novice. Where is the Current event
located?

Klatuu said:
If you mean the Visible property of the text box, it doesn't really matter,
because you are changing it on each record.
Since I don't know what your control names really are, I made some up, but
the code I posted should work. Did you put it in the Current event of the
form?

One thing I did leave out, is how to handle new records. As is, it would
display the control for new records.

One other thing is how you worded your original post. You first said:
"I have a text box in a form and I would only like it to display data if a
seperate field in the table is True"

This would indicate a Boolean(Yes/No) data type field.

Then you said:
"I only want it to display when Tbl_Hotels.[Brand] = "RD""

Now we are talking about a text field. I did write the code for the text
field. Remember, when you are working in a form, you don't use the table's
field names. You use the form's control names. If you use the form wizard or
drag the fields off the field list onto the form, Access gives the control
the same name as the field. This is bad. Not only can it confuse us humans,
Access can sometimes get it wrong. So be sure your naming is good and you
are using the form control names.

Now here is the explanation:

This part:
Me.txtBrand = "RD"
will return True if the control is equal to "RD" and False if it is not

This part:
Me.txtRequiredProductReference.Visible =
Will set the Visible property of the control based on what is on the right
of the = sign.

So if you say:
Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"
it will evaluate the expression on the right side of the first = and return
either True or False, thus setting the Visible property.

We put it in the form's Current event because it fires every time the
current record changes. This includes when you open the form.

Sorry, but I know that works, it is a matter of getting the naming correct
and looking for the proper value.
--
Dave Hargis, Microsoft Access MVP


Chris said:
I tried that and they did not display. Do I have to set the visible field to
Yes?

:

Use the form's Current Event. You posted field names, but those wont help.
You need to use the form's control names. Making up "guess " names, it would
be something like:

Me.txtRequiredProductReference.Visible = Me.txtBrand = "RD"

--
Dave Hargis, Microsoft Access MVP


:

I have a text box in a form and I would only like it to display data if a
seperate field in the table is True. Is this something that can be done?

Example.

Tbl_PIP_Items.[Required Product Reference] is loaded in a form. I only want
it to display when Tbl_Hotels.[Brand] = "RD". Can this be done?
 

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

Back
Top