0

I have a macro in Access 2016 using a for loop to check the values of check boxes. I want to submit the values to a table. I don't want the standard checkbox value for true (-1) I want the value of a 'rolling' count of which has been checked.

e.g. CB1 CB2 CB3 CB4

If only CB1 and CB4 are checked then I want to submit to the table the values 1 for CB1 and 2 for CB4.

My for loop is:

For i = 1 To 8
If Me.Controls("CP" & i) = -1 Then
"CP" & i = I    'ISSUE IS HERE
Debug.Print Me.Controls("CP" & i)
End If
Next i

How do I refer to the variable value? so CP & I = CP1, CP2, CP3, CP4 etc...

1
  • 1
    Me.Controls("CP" & i)= I? Commented Nov 23, 2017 at 11:55

2 Answers 2

1

variable names, are static you cannot use the syntax "CP" & i to access a variable. you have to use array instead.

Dim arrCP(8)
For i=Me.controls("CP" & i)=-1 then
arrCP(i)=i
debug.print arrCP(i)
end if
next i
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe something like this, using a countTrue to determine the number you would like to display.

Dim countTrue As Long: countTrue = 0
For i = 1 To 8
    If Me.Controls("CP" & i) = -1 Then
        countTrue = countTrue + 1
        Me.Controls("CP" & i) = countTrue
        Debug.Print Me.Controls("CP" & i)
    End If
Next i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.