How do I conditionally hide controls in an Access form?

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

Guest

I would like to have a set of controls appear when a certain control shows
"Yes". The help menu says to build a macro to perform this task, but doesn't
tell me how to do this. Can anyone help? Example? OFI check box = "yes",
then x, y, and z boxes appear.
 
Sbickley,

Well, if OFI is a checkbox, it's value is unlikely to be "yes", as this
is text.

It depends when you want this to occur. Most likely you will want your
macro on the On Current event property of the form, and you may also
want it on the After Update event of the OFI checkbox, so the visibility
of x, y, and z is toggled when you tick/untick the checkbox.

The macro itself will use the SetValue action. In the macro design
window, if you can't see the Condition column, select Condition from the
View menu. Then, the macro will be like this...

Condition: [OFI]=-1
Action: SetValue
Item: [x].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: Yes

Condition: [OFI]=0
Action: SetValue
Item: [x].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: No
 
I have a similar problem and have tried this, but following typing

[control name].[visible]

into the Item: field of the setvalue action of the macro I get the error
"The object doesn't contain the automation object 'Visible' "

It seems that it is treating the command visible as a control name.

What is going on?


Steve Schapel said:
Sbickley,

Well, if OFI is a checkbox, it's value is unlikely to be "yes", as this
is text.

It depends when you want this to occur. Most likely you will want your
macro on the On Current event property of the form, and you may also
want it on the After Update event of the OFI checkbox, so the visibility
of x, y, and z is toggled when you tick/untick the checkbox.

The macro itself will use the SetValue action. In the macro design
window, if you can't see the Condition column, select Condition from the
View menu. Then, the macro will be like this...

Condition: [OFI]=-1
Action: SetValue
Item: [x].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: Yes

Condition: [OFI]=0
Action: SetValue
Item: [x].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: No

--
Steve Schapel, Microsoft Access MVP

I would like to have a set of controls appear when a certain control shows
"Yes". The help menu says to build a macro to perform this task, but doesn't
tell me how to do this. Can anyone help? Example? OFI check box = "yes",
then x, y, and z boxes appear.
 
Leave your fields control alone and type the function in the same Section's
Event - OnPrint area as a Procedure in the Code Building area.

Me.[YourField].Visible = (Me.[YourCheckBox] = False)

You can replace the False with True if your Checkbox is marked "Yes"

Good Luck!

Tim Colbourn said:
I have a similar problem and have tried this, but following typing

[control name].[visible]

into the Item: field of the setvalue action of the macro I get the error
"The object doesn't contain the automation object 'Visible' "

It seems that it is treating the command visible as a control name.

What is going on?


Steve Schapel said:
Sbickley,

Well, if OFI is a checkbox, it's value is unlikely to be "yes", as this
is text.

It depends when you want this to occur. Most likely you will want your
macro on the On Current event property of the form, and you may also
want it on the After Update event of the OFI checkbox, so the visibility
of x, y, and z is toggled when you tick/untick the checkbox.

The macro itself will use the SetValue action. In the macro design
window, if you can't see the Condition column, select Condition from the
View menu. Then, the macro will be like this...

Condition: [OFI]=-1
Action: SetValue
Item: [x].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: Yes

Condition: [OFI]=0
Action: SetValue
Item: [x].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: No

--
Steve Schapel, Microsoft Access MVP

I would like to have a set of controls appear when a certain control shows
"Yes". The help menu says to build a macro to perform this task, but doesn't
tell me how to do this. Can anyone help? Example? OFI check box = "yes",
then x, y, and z boxes appear.
 
Thanks Robbie, however the Visual Basic baffled me a bit so I ended up
Enabling the controls conditional on what was entered in another control...
Tim

Robbie Doo said:
Leave your fields control alone and type the function in the same Section's
Event - OnPrint area as a Procedure in the Code Building area.

Me.[YourField].Visible = (Me.[YourCheckBox] = False)

You can replace the False with True if your Checkbox is marked "Yes"

Good Luck!

Tim Colbourn said:
I have a similar problem and have tried this, but following typing

[control name].[visible]

into the Item: field of the setvalue action of the macro I get the error
"The object doesn't contain the automation object 'Visible' "

It seems that it is treating the command visible as a control name.

What is going on?


Steve Schapel said:
Sbickley,

Well, if OFI is a checkbox, it's value is unlikely to be "yes", as this
is text.

It depends when you want this to occur. Most likely you will want your
macro on the On Current event property of the form, and you may also
want it on the After Update event of the OFI checkbox, so the visibility
of x, y, and z is toggled when you tick/untick the checkbox.

The macro itself will use the SetValue action. In the macro design
window, if you can't see the Condition column, select Condition from the
View menu. Then, the macro will be like this...

Condition: [OFI]=-1
Action: SetValue
Item: [x].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: Yes

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: Yes

Condition: [OFI]=0
Action: SetValue
Item: [x].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [y].[Visible]
Expression: No

Condition: ...
Action: SetValue
Item: [z].[Visible]
Expression: No

--
Steve Schapel, Microsoft Access MVP


sbickley wrote:
I would like to have a set of controls appear when a certain control shows
"Yes". The help menu says to build a macro to perform this task, but doesn't
tell me how to do this. Can anyone help? Example? OFI check box = "yes",
then x, y, and z boxes appear.
 
Back
Top