Julius
Julius

Reputation: 129

Using variable in IF clause

I´m programming some Form in Access 2010 and want to check some Radio Button if they are checked or not.

I want to use an until Loop because there are 38 questions which would be to much to check by every row.

I used this but it´s not working

Me.OptionQ(lNum).Value

Here´s the complete IF statement I want to use.

Dim lNum AS Long

lNum = 1


Do Until lNum = 39


 If Me.OptionQ(lNum).Value = 1 Then
     MsgBox "Option 1 is selected"
 ElseIf Me.OptionQ(lNum).Value = 2 Then
     MsgBox "Option 2 is selected"
 ElseIf Me.OptionQ(lNum).Value = 3 Then
     MsgBox "Option 3 is selected"
 Else
     MsgBox "Please choose an answer for every question."
     Exit Do
 End If
lNum = lNum + 1

Loop

I searched a lot, but it seems there is no way to do it like this.

Upvotes: 1

Views: 52

Answers (1)

HansUp
HansUp

Reputation: 97101

I think you're saying you have a set of 38 controls named OptionQ1 through OptionQ38.

If that is correct, you can inspect the value of each of those controls and do what you want with simpler code.

For lNum = 1 To 38
    Select Case Me.Controls("OptionQ" & lNum).Value
    Case 1 To 3
        MsgBox "Option " & Me.Controls("OptionQ" & lNum).Value & _
            " is selected"
    Case Else
        MsgBox "Please choose an answer for every question."
        Exit For
    End Select
Next

Upvotes: 1

Related Questions