How to make fields invisible, based on Yes/No?

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

Guest

Hello,

I have a form that I want to use for data entry into a table. I want to make some fields only visible if the answer to the first question is "Yes" (check box). How do I do this? I can't figure this out from the Help in Access. I know there is some property, but I'm not sure where that goes, or what the correct syntax is.

Thanks in advance.
 
Hello Gabriel (it's my nephew's name too!)

On the 'current' event of your form, keep that fields invisible:

Me!yourfield1.visible = false
Me!yourfield2.visible = false

On the 'after updade' of your checkbox put this:

If Me.Your checkbox = "yes" Then
Me!yourfield1.visible = true
Me!yourfield2.visible = true
nextfield.SetFocus
Else
Exit Sub
End If

I am not sure about "yes" or "no", if doesn't work, try 1 and -1

Good Luck

Marco
São Paulo - Brasil
Gabriel said:
Hello,

I have a form that I want to use for data entry into a table. I want to
make some fields only visible if the answer to the first question is "Yes"
(check box). How do I do this? I can't figure this out from the Help in
Access. I know there is some property, but I'm not sure where that goes, or
what the correct syntax is.
 
Hello,

I have a form that I want to use for data entry into a table. I want to make some fields only visible if the answer to the first question is "Yes" (check box). How do I do this? I can't figure this out from the Help in Access. I know there is some property, but I'm not sure where that goes, or what the correct syntax is.

Thanks in advance.

Code the AfterUpdate event of the CheckBox,
and the Form's Current event:

[Control1].Visible = [CheckBox] = -1
[Control2].Visible = [CheckBox] = -1

That's all.
 
Hello

In the same example, try isnull

if isnull(me.yourcheckbox) then...
or if not isnull(me.yourcheckbox) then
....visible=true or false



make some fields only visible if the answer to the first question is "Yes"
(check box). How do I do this? I can't figure this out from the Help in
Access. I know there is some property, but I'm not sure where that goes, or
what the correct syntax is.
Thanks in advance.

Code the AfterUpdate event of the CheckBox,
and the Form's Current event:

[Control1].Visible = [CheckBox] = -1
[Control2].Visible = [CheckBox] = -1

That's all.
 
Sorry, but none of these are working. Not sure if I am doing this right.

Here is my code:

This one doesn't do anything. I have it in the Form Current Event and AfterUpdate of "PM_Report_Req" [checkbox]
=PM_Report_Freq.Visible=[PM_Report_Req]=-1

If I try
Me!PM_Report_Freq.visible = false in the form Current Event and
= If me.PM_Report_Req = "yes" then
me!PM_Report_Freq.visible = true in the AfterUpdate of "PM_Report_Req" [checkbox]
then I get an error --- "MS Access can't find the macro 'Me!PM_Report_Freq'

and if I'm not sure where I should put the last suggestion.

Help is MUCH appreciated.
 
Gabriel,
Gabriel,

You have several different problems.
1) You are writing code, but you are NOT placing the code in a code
window. You are attempting to write the code directly on the event
line.
2) The code you are writing, if you placed it in a code window is
incorrectly written.
Read my comments below and then I'll tell you how to access the event
code window.


Sorry, but none of these are working. Not sure if I am doing this right.

Here is my code:

This one doesn't do anything. I have it in the Form Current Event and AfterUpdate of "PM_Report_Req" [checkbox]
=PM_Report_Freq.Visible=[PM_Report_Req]=-1

You are not writing the code correctly.
The line
=PM_Report_Freq.Visible=[PM_Report_Req]=-1
should be written like this:

[PM_Report_Freq].Visible=[PM_Report_Req]=-1
assuming [PM_Report_Req] is the Check Box field.
Notice that there is no = sign in front of [PM_Report_Freq]
And it must be placed in the event code, not on the event line.
If I try
Me!PM_Report_Freq.visible = false in the form Current Event and
= If me.PM_Report_Req = "yes" then
me!PM_Report_Freq.visible = true in the AfterUpdate of "PM_Report_Req" [checkbox]
then I get an error --- "MS Access can't find the macro 'Me!PM_Report_Freq'

This line,
Me!PM_Report_Freq.visible = false
(as code), is written OK.
These next lines (as code) are incorrectly written.
= If me.PM_Report_Req = "yes" then
me!PM_Report_Freq.visible = true
Should read:
If me.PM_Report_Req = Yes then
me!PM_Report_Freq.visible = true

And then you must add code to make it not visible if the check box is
false.
And then you must finish with an End If
Notice that I have used Yes without the quotes.
The value of Yes, in access, is a number value either -1 or 0. A
number must not be surrounded with the quotes.

Here is how to get into the Event code window to write the code.
Display the Form's property sheet.
Click on the Event tab.
On the line that says Current, write
[Event Procedure]
A button with 3 dots will appear.
Click on that button.
The Current event code window will appear.
It will have 2 already existing lines of code.
Between those 2 lines write:

[PM_Report_Freq].Visible=[PM_Report_Req]=-1

Exit the code window by clicking on the upper right hand corner X.
Now click on the Check Box control and click on the Event tab.
Find the After Update event line.
On that line write [Event Procedure].
Follow the previous instructions and enter the same line of code.
Exit the window.
You are done.

Here is how to write the second example you posted. It will work fine
after you correctly enter it in both the Current and AfterUpdate
events. Notice it takes much more code than the one line I suggested.

If me![PM_Report_Req] = yes then
me![PM_Report_Freq].visible = True
Else
me![PM_Report_Freq].visible =False
End If

I hope this gets you started again in the right direction.
 
Back
Top