Lightwave
Ad astra
- Local time
- Today, 08:40
- Joined
- Sep 27, 2004
- Messages
- 1,537
Access 2003 designing a form.
I have three yes no fields and I want to show the fields if they are yes and not show them if their value is no.
I can do it as follows
On Load Event
Now that does work and for three fields with only 2 values its not too onerous I get eight IF statements that I have to make up.
But if I want to do that on eight fields I'd have to have a massive statement with 2 ^ 8 If statements
So I was wondering whether I could do more succintly as follows..
The second code is much shorter and additionally it is not necessary to have every combination of the three fields as the fields are tested consecutitvely.
Unfortunately when I try the second coding in a form it doesn't seem to work with it missing some of the switches.
Can someone indicate what the optimal way of doing this sort of If switch is.
Do you just have to go through all the possibilities or is there a way of consecutively going through switches so you define each individual switch and not the sum of all of them.??
Or do you think there's a glitch in my form and the second code should work?
I think the problem with the second one is that it goes through and tests and so long as its consistent with the result its fine. Unfortunately as soon as you trigger a single switch it jumps to the Else section therefore potentially missing one or more IFs
Thanks in advance
I have three yes no fields and I want to show the fields if they are yes and not show them if their value is no.
I can do it as follows
On Load Event
Code:
If Field1.Value = Yes and Field.Value2.Value = Yes and Field3.Value = Yes then
Field1.Visible = True
Field2.Visible = True
Field3.Visible = True
Else
If Field1.Value = No and Field2.Value = Yes and Feild3.Value = Yes then
Field1.Visible = False
Field2.Visible = True
Field3.Visible = True
and continuing for 2 * 2 * 2 options...
and finishing with 8 End Ifs
Now that does work and for three fields with only 2 values its not too onerous I get eight IF statements that I have to make up.
But if I want to do that on eight fields I'd have to have a massive statement with 2 ^ 8 If statements
So I was wondering whether I could do more succintly as follows..
Code:
If Field1.Value = False then
Feild1.Visible = False
If Field2.Value = False then
Field2.Visible = False
If Field3.Value = False then
Field3.Value = False
Else
End If
End If
End If
The second code is much shorter and additionally it is not necessary to have every combination of the three fields as the fields are tested consecutitvely.
Unfortunately when I try the second coding in a form it doesn't seem to work with it missing some of the switches.
Can someone indicate what the optimal way of doing this sort of If switch is.
Do you just have to go through all the possibilities or is there a way of consecutively going through switches so you define each individual switch and not the sum of all of them.??
Or do you think there's a glitch in my form and the second code should work?
I think the problem with the second one is that it goes through and tests and so long as its consistent with the result its fine. Unfortunately as soon as you trigger a single switch it jumps to the Else section therefore potentially missing one or more IFs
Thanks in advance
Last edited: