Setting Field values in a For Next Loop

C

Chris B

I have number of fields with the same name except the a
number value at the end, (PACS_QE1, PACS_QE2, PACS_QE3,
etc...) I can set the controls for these fields in a For
Loop with code like the following:

For x = 1 to 10
Me.Controls("PACS_QE" & x).Enabled = False
Next

Now what I need to add is the same logic to set all the
field values to 0 in the same loop. I am sure it is
simple, so let me have it. P-L-E-A-S-E!

Chris
 
A

Allen Browne

For x = 1 to 10
Me.Controls("PACS_QE" & x) = 0
Next

In general, Chris, repeating fields like that indicate that you need to
break the table down into a related table.
 
M

Marshall Barton

Chris said:
I have number of fields with the same name except the a
number value at the end, (PACS_QE1, PACS_QE2, PACS_QE3,
etc...) I can set the controls for these fields in a For
Loop with code like the following:

For x = 1 to 10
Me.Controls("PACS_QE" & x).Enabled = False
Next

Now what I need to add is the same logic to set all the
field values to 0 in the same loop.


Me.Controls("PACS_QE" & x) = 0
 
C

Chris B

I have tried this, and it does not work. I must use this
format in this application, it deals with tracking
question results from written exams of 45-60 questions, no
choice. But thanks
 
C

Chris B.

I have tried this, and the error message I get is that
value can not be set to this object.
 
A

Allen Browne

Try using a string variable, and/or being explicit about the Value property:

Dim strControl As String
For x =1 to 10
strControl = "PACS_QE" & x
Me(strControl).Value = 0
Next
 

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