make field name in code variable for vb code loop

I have a form with 20 fields on it with the following names:  COL_1, COL_2...COL_20  
I need to check each one of these dropdown fields to see if a predefined text has been selected.  Problem is I can't figure out how to make the number part of the field name a variable or what to Dim it as.

    Dim ColumnNum As ??????, intCount As Integer
    intCount = 1
    Do Until intCount = 20
        ColumnNum = COL_ & intCount
        If ColumnNum = "CompToRcvd" Then
            MsgBox "yes"
            MsgBox "no"
        End If
        intCount = intCount + 1
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Are these fields in the underlying recordset, or are they controls on the form?  It makes a difference.  Here's a basic template:

For x = 1 to 20
    Me.Controls("COL_" & x) '<--- references a control COL_x
    Me.Recordset.Fields("COL_" & x)  '<--- references a field in the underlying data

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dim c As Control
For Each c In Me.Controls
If c.ControlType = acTextBox Then
    MsgBox & " " & c.Value
End If
Next c

if combo use:

if list box
woodan1Author Commented:
That's the answer.  Thanks.

    Dim x As Integer
    x = 1
    For x = 1 To 20
        If Me.Controls("COL_" & x) = "CompToRcvd" Then
            Debug.Print "Yes " & "COL_" & x
            Debug.Print "No " & "COL_" & x
        End If
woodan1Author Commented:
Sorry McDougall, didn't catch your response until after I accepted.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.