Need help w/ IF ELSE (and maybe For Loop)

T

Tom

Hi:

I need some help with the function below (&&&s)... more specifically, I need
some help w/ the "If IsNull(Me.Frame5) Then" routine.

Here's what I have:
- form with tab control
- Next (and Previous) command button are in form footer
- each tab (page) has multiple option groups. Each group has 6 radio
buttons.
- Next_Click routine has For Loop that does do the following: 1) when Next
is clicked, checks if each option group has an "answer", 2) if any one
option group does not have an answer, it places an image (questionmark) next
to the question and gives user a "visual reminder" to complete the
unanswered question(s)
- this process worked great thus far

Now, I have made a "conceptual change" in respect to the options groups.
This change is such as:
- instead of answering all questions, a user may or may not answer all
question because of "question hierarchy".
- for instance, there might be a "parent question" which has "children
questions".
- if a parent question is answered with "No" (or radio button value "0"),
then children questions will be disabled and their values automatically
become "0" as well.
- however, if the parent question is answered with "Yes" (or radio button
value "5") then the user must complete all of the subordinate children
questions as well
- essentially something like this: "Do you work with customers"? (parent
question)... if "no" skip to question XYZ, if "yes" please complete the next
3 questions (children questions)...

Okay, here's now the problem w/ my ForLoop that has been working fine until
this conceptual change:

First though, let me say that I just added the 9 lines (IF ELSE statement)
for the "Me.Frame5".

Problem w/o the IF ELSE:
==================
- if I answered "no" and skipped e.g. 3 questions, I could not move to the
next page. Besides, the question mark image was placed next to the 3
unanswered questions (which were hidden)... so I had images "next to
nothing"

Problem w/ the IF Else:
================
- although the IF ELSE takes care of the ladder problem ("I can't move to
next page"), I must get the images if I do answer the parent question with
"Yes" (or radio button value "5"). BTW, parent question only have those 2
values (0 and 5... essentially parent questions are of boolean type... Yes
or No).

So, here's my question now: Why does the IF ELSE works fine as a
workaround for "No" answers, but it doesn't work for "Yes" questions... here
I'm missing my images (and I can move to then next page) even though those
questions must be answered and I should not move to the next page until
that's the case.

Thanks so much in advance,
Tom

P.S.... sorry for this long-winded problem...



&&&&&&&&&&&&&&&&&&&
Private Sub Next_Click()

Dim strSQL As String
Dim ctl As Control, strNL As String
strNL = ""

If IsNull(Me.Frame5) Then
Me.Frame6.Enabled = False
Me.Frame7.Enabled = False
Me.Frame8.Enabled = False
Else
Me.Frame6.Enabled = True
Me.Frame7.Enabled = True
Me.Frame8.Enabled = True
End If


For Each ctl In Me.TabControl1.Pages(TabControl1).Controls
'Checks to determine control is text box
If ctl.ControlType = acOptionGroup Then
If ctl.Enabled = True Then
If IsNull(ctl) Then 'If question is unanswered
strFrame = ctl.Name 'Determines the QuestionMark #
(image)
Debug.Print strFrame
strNL = strNL & strFrame & ","
intFr = Mid(strFrame, 6, Len(strFrame) - 5)
Me("QuestionMark" & intFr).Visible = True 'Makes
QuestionMark image visible
End If
End If
End If
Next ctl

If Len(strNL) > 0 Then
Dim ctrl As Control
strNL = Left(strNL, Len(strNL) - 1)
MsgBox "You must complete all questions on this page before you
can move to the next page.", vbInformation, "Missing Data"
If InStr(strNL, ",") > 0 Then
strFrame = Left(strNL, InStr(1, strNL, ",") - 1)
Else
strFrame = strNL
End If
Me(strFrame).SetFocus
Exit Sub
End If
End Sub
&&&&&&&&&&&&&&&&&&&
 
B

Barry-Jon

Try:

If (Me.Frame5) Then
Me.Frame6.Enabled = True
Me.Frame7.Enabled = True
Me.Frame8.Enabled = True
Else
Me.Frame6.Enabled = False
Me.Frame7.Enabled = False
Me.Frame8.Enabled = False
End If

If frame5 is your parent question and is a boolean then it is either
true or false and never null - that would explain why it works for no
but not for yes as 'IsNull(Me.Frame5)' never equates to true.

Let me know how you get on...
 
T

Tom

Barry-Jon:

Thanks for the reply.

I inserted your suggested code.. it has the same outcome.

Okay, maybe I "misspoke" in respect to the boolean info. The Frame5 is
just another optiongroup that also has six radio button. Visually, I only
treat them as Y or N. What I mean by that, when someone opens the form,
the OnOpen event automatically hides the 4 radiobuttons (1,2,3,4). And I
also have changed their tooltips...

So, Frame5 will either have value "0" or value "5". If "0" is selected
and any of the 3 option groups (6, 7, 8) has not answer, the IF statement
disables then so that the ForLoop won't throw the image and I can move to
the next page via clicking "Next".

That's why I so baffled, if "5" (the only other alternative to "0") has been
selected in Frame5, frames 6:8 should stay enabled and the ForLoop should
kick in and throw the images if any of those 3 options groups don't have a
value. I mean, isn't it a "simple IF ELSE" routine...

.... but then, reality is that the images are not thrown if 6:8 are
unanswered while 5 = Yes.

Any additional suggestions?
 
D

Dan Artuso

Hi,
If Frame5 will be a 0 or 5, why are you checking for Null???
It will never be Null. It will be 0 or 5.
 
T

Tom

Barry-Jon:

I figured it out... I had 3 lines in the Frame5AfterEvent that set the
values ="" for the 3 children questions.
 
R

rkc

Tom said:
I figured it out... I had 3 lines in the Frame5AfterEvent that set the
values ="" for the 3 children questions.

Just in case you'd like to know, controls that make up an
option group are children of the optionGroup. They can be
accessed in a for each loop like so:

Dim ctl As Access.Control
For Each ctl In Me.Frame0.Controls
Debug.Print ctl.Name
Next

A method can be written to set the visible property of
each option button in the optionGroup like so:

Private Sub ShowOptionButtons(optGrp As Access.OptionGroup, _
state As Boolean)
Dim ctl As Access.Control
Dim opt As Access.OptionButton
For Each ctl In optGrp.Controls
If ctl.ControlType = acOptionButton Then
Set opt = ctl
opt.Visible = state
End If
Next

Set ctl = Nothing
Set opt = Nothing

End Sub


Then this:

ShowOptionButtons Me.Frame6, False

can replace this:

'After update, hides all radio buttons for Q6 (Q5 is "parent question")
Me.Option6_0.Visible = False
Me.Option6_1.Visible = False
Me.Option6_2.Visible = False
Me.Option6_3.Visible = False
Me.Option6_4.Visible = False
Me.Option6_5.Visible = False


in multiple places in your code.
 
T

Tom

Thanks... I'll give it a try.
--
Thanks,
Tom


rkc said:
Just in case you'd like to know, controls that make up an
option group are children of the optionGroup. They can be
accessed in a for each loop like so:

Dim ctl As Access.Control
For Each ctl In Me.Frame0.Controls
Debug.Print ctl.Name
Next

A method can be written to set the visible property of
each option button in the optionGroup like so:

Private Sub ShowOptionButtons(optGrp As Access.OptionGroup, _
state As Boolean)
Dim ctl As Access.Control
Dim opt As Access.OptionButton
For Each ctl In optGrp.Controls
If ctl.ControlType = acOptionButton Then
Set opt = ctl
opt.Visible = state
End If
Next

Set ctl = Nothing
Set opt = Nothing

End Sub


Then this:

ShowOptionButtons Me.Frame6, False

can replace this:

'After update, hides all radio buttons for Q6 (Q5 is "parent question")
Me.Option6_0.Visible = False
Me.Option6_1.Visible = False
Me.Option6_2.Visible = False
Me.Option6_3.Visible = False
Me.Option6_4.Visible = False
Me.Option6_5.Visible = False


in multiple places in your code.
 
T

Tom

Dan,
thanks for the reply... the problem was something else... I posted another
comment 2 messages below yours.
 

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

Top