My Stupid Loop Idea

MaliciousMike

Registered User.
Local time
Today, 19:34
Joined
May 24, 2006
Messages
118
I've got 20 checkboxes which i need to do the same thing but individually.
Code:
If IsNull(DLookup("[question 1]", "qryQuestions")) Then
    chkQuestion1.Visible = False
Else
    chkQuestion1.Visible = True
End If


I tried this:
Code:
Dim loopy As Integer
Dim tmpquest As String

For loopy = 1 To 20
    tmpquest = "question " & loopy
    tmpCheck = "chkQuestion" & loopy
    If IsNull(DLookup(tmpquest, "qryQuestions")) Then
        tmpCheck.Visible = False
    Else
        tmpCheck.Visible = True
    End If
Next loopy

tmpquest works.
tmpcheck doesn't.

I tried dimming tmpcheck as lots of things but no luck.

Any help?
 
Instead of finding out what the questions are, simply name all checkboxes "Check1, Check2, ..."

then use this code

Code:
For i = 1 to 20
     If IsNull(Blah) Then
          Me.Check(i).Visible=False
     End If
Next i

This is off the top of my mind, so it's up to you to fix the punctuation.
 
Banana said:
Instead of finding out what the questions are, simply name all checkboxes "Check1, Check2, ..."

then use this code

Code:
For i = 1 to 20
     If IsNull(Blah) Then
          Me.Check(i).Visible=False
     End If
Next i

This is off the top of my mind, so it's up to you to fix the punctuation.

the checkboxes are called "chkQuestion1, chkQuestion2,..."

I tried:
chkQuestion(loopy).Visible = False

to no avail.
says that chkQuestion isn't defined, but i don't know what to dim it as.

I have to leave the office now, but i'll be back tomorrow to grab this database by the balls and finish the bugger!
 
Hmm.. it did work for me before...

Let me look at my code again.
 
brr..

For i = 1 to 20
If IsNull(Blah) Then
Me.Controls("chkQuestion" & i).Visible=False
End If
Next i
 

Users who are viewing this thread

Back
Top Bottom