dependent fields

M

Miguel Vivar

How can I make appear a set of fields after an awswer has been chosen? For
instance, if the anwser was yes, then a set of fields appear, and if the
answer was no, a distinct set of fields appear.
 
K

Klatuu

You will need two queries. One with the fields for Yes and the other with
fields for No.

I don't know where you are answering the question, but let's assume it is a
CheckBox on a form. If so, in the After Update event of the checkbox:
If me.MyCheckBox = True
strQryToUse = "qselYesAnswers"
Else
strQryToUse = "qselNoAnswers"
End If
 
S

Steve Schapel

Miguel,

Assuming I understand you correctly, her is an example of code...

Dim YesAnswer As Boolean
YesAnswer = MsgBox("What is the question?", vbYesNo) = vbYes
Me.1stControlToSeeWhenYes.Visible = YesAnswer
Me.2ndControlToSeeWhenYes.Visible = YesAnswer
Me.1stControlToSeeWhenNo.Visible = Not YesAnswer
Me.2ndControlToSeeWhenNo.Visible = Not YesAnswer
 
M

Miguel Vivar

Hi Klatuu
I get the error Sintax problem when I try t enter the codes you gave me. I
need a little more specific steps.
For instance, how it will recognize the query where the yes fields are and
the query for the no fields are?
The name of my queries are very simple: Yes and No.
I appreciate your help
Thanks
 
S

Steve Schapel

Miguel,

When do you want the question to be asked, and when do you want the
visibility of the controls on your form to be adjusted? When you first
open the form? When you move to another record? When you first open
the database? When you click your mouse on a button? Lunch time?
 
M

Miguel Vivar

Steve:
The question is a check box (yes/no). When the participant answers "yes" I
would like a set of questions to appear next to this field. If the
participant answers "no" I would like a new set of questions to appear next
to this field. The yes/no question is the very first question in the form and
the visibility of the controls to be adjusted should be when I move to the
next field (if that's possible). Here is an example:
Do you work:
yes - no
if answered "yes" then a set of question next to this filed appear in the
form according to this choice.
If the question is answered "no" then a new set of questions appear in the
form next to the first field with choices yes/no.
I hope this is understandable.
This is another question for the choices that Kaluu gave me. I used the
codes that Kaluu gave me about the same question, and I plugged them in the
after update (first choice), but an error message appears about the syntax.
Where should I write these codes in the after update? The first choice? This
is an alternate solution that Kallu gave me.
Thank you for your support
 
S

Steve Schapel

Miguel,

In that case, you would write your code on the After Update event
property of the check box. The code would be the equivalent of this...

Me.1stQuestionToSeeWhenYes.Visible = Me.NameOfCheckbox
Me.2ndQuestionToSeeWhenYes.Visible = Me.NameOfCheckbox
Me.1stQuestionToSeeWhenNo.Visible = Not Me.NameOfCheckbox
Me.2ndQuestionToSeeWhenNo.Visible = Not Me.NameOfCheckbox
.... etc
 
M

Miguel Vivar

Steve:
The words 1st and 2nd are not accepted as codes as I write the following:
Me.1stQuestionToSeeWhenYes.Visible = Me.NameOfCheckbox
Me.2ndQuestionToSeeWhenYes.Visible = Me.NameOfCheckbox
Me.1stQuestionToSeeWhenNo.Visible = Not Me.NameOfCheckbox
Me.2ndQuestionToSeeWhenNo.Visible = Not Me.NameOfCheckbox
..... etc

Is there another way to do it?

Miguel
 
S

Steve Schapel

Miguel,

You didn't tell us what are the names of the controls you are referring
to. When I put, for example, 1stQuestionToSeeWhenYes it is to refer to
the name of one of the controls on your form that you want to show when
you tick the checkbox. Similarly, NameOfCheckbox is supposed to refer
to the name of your checkbox. In your code, you are supposed to
substitute the actual names of your controls.
 
Top