Need help with modifying FOR LOOP

T

Tom

I need some help with modifying the FOR loop below.

This loop checks if any options groups have not been selected on the active
worksheet tab. If yes (some radio buttons have not been selected), it
brings focus to the option group control.

Now, here's what I want to do.
1. Instead of "just bringing focus" to the control, I also want to make a
small image visible.
2. I placed as many small images onto the form as I have options groups
(right now 21)... while 18 options groups
are currently "sitting" on Tab1, the remaining 3 options groups reside on
Tab2
3. The iamge control names are: "QuestionMark1", "QuestionMark2",
"QuestionMark3", ... "QuestionMark21"



***** BEGIN CURRENT FUNCTION ********************

Dim ctl As Control

For Each ctl In Me.TabControl1.Pages(TabControl1).Controls
' Check to see if control is text box.
If ctl.ControlType = acOptionGroup Then
If ctl.Enabled = True Then
If IsNull(ctl) Then 'If question unanswered
MsgBox "You must complete all questions on the survey.",
vbInformation, "Missing Data"
ctl.SetFocus 'Brings survey participant to the missing answer
Exit Sub 'Leave the routine
End If
End If
End If
Next ctl

***** END CURRENT FUNCTION ********************




I want the enviosioned function to be rewritten so that it loops through the
options groups and makes the image visible where option group is unanswered.

I added 2 lines into the function where I think images are made not
visible/visible: "<<< logical approach, but wrong syntax I guess"




***** BEGIN ENVISIONED FUNCTION ********************

Dim ctl As Control

For Each ctl In Me.TabControl1.Pages(TabControl1).Controls
Me.QuestionMark#.Visible = False <<< logical
approach, but wrong syntax I guess
' Check to see if control is text box.
If ctl.ControlType = acOptionGroup Then
If ctl.Enabled = True Then
If IsNull(ctl) Then 'If question unanswered
MsgBox "You must complete all questions on the survey.",
vbInformation, "Missing Data"
ctl.SetFocus 'Brings survey participant to the missing answer
Me.QuestionMark#.Visible = True <<< logical
approach, but wrong syntax I guess
Exit Sub 'Leave the routine
End If
End If
End If
Next ctl

***** END ENVISIONED FUNCTION ********************



Can anyone help me out rewrite this function?

Thanks,
Tom
 
G

Guest

Tom,

Maybe this will help.. I couldn't test all of the code, but it should work....

One big problem is to know *which* QuestionMark image to make visible. I
didn't know if the option group name had the same number as the question
mark image, so I took the easy way out and used the TAG property of the
option group to store the number of the question mark for the option group.

So, if the first option group name is Frame6 and the image "QuestionMark1"
should be visible if no answer was selected, then put 1 in the tag
property for the frame.
Add a number to all of the option groups "Tag" property.

Here is the code (watch for line wrap):

'SEE the page at
'
' http://www.mvps.org/access/forms/frm0003.htm
'
' Excelent reference
'
' ***** BEGIN ENVISIONED SUB ********************
Dim ctl As Control
Dim i As Integer '<< for image number

'first, hide all question mark images
For Each ctl In Me.TabControl1.Pages(TabControl1).Controls
' check to see if an image and name starts with QuestionMark (12
chrs long)
If ctl.ControlType = acImage And Left(ctl.Name, 12) = "QuestionMark"
Then
' get image number by parsing the name
i = Right(ctl.Name, Len(ctl.Name) - 12)
' now hide the image
Me("QuestionMark" & i).Visible = False
End If
Next

' next, check for missing answers
For Each ctl In Me.TabControl1.Pages(TabControl1).Controls
' Check to see if control is Option Group
If ctl.ControlType = acOptionGroup Then
If ctl.Enabled = True Then
If IsNull(ctl) Then 'If question unanswered
'show question mark <<< number stored in the option
group TAG property>>
If IsNumeric(ctl.Tag) And IsNz(ctl.Tag, 0) > 0 Then
Me("QuestionMark" & ctl.Tag).Visible = True
Else
MsgBox "Missing a number in the tag property for " &
ctl.Name
End If
MsgBox "You must complete all questions on the survey.",
vbInformation, "Missing Data"
ctl.SetFocus 'Brings survey participant to the
missing answer
Exit Sub 'Leave the routine
End If
End If
End If
Next ctl
' ***** END ENVISIONED SUB ********************

HTH

Steve
 

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