Setting Field values in a For Next Loop

  • Thread starter Thread starter Chris B
  • Start date Start date
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
 
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.
 
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
 
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
 
I have tried this, and the error message I get is that
value can not be set to this object.
 
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
 
Back
Top