Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Objects and Variables 1

Status
Not open for further replies.

neiljabba

IS-IT--Management
May 22, 2003
86
GB
Hello folks

Ive been trying to reduce my code length using a variable assigned to a checkbox object e.g.

CheckBoxa.Value

where "a" is a loop counter but keep getting object not defined errors. I understand why but is there a method I can use to allow me to write the same code for 30 boxes and loop it.
 
Hi neiljabba,

Checkboxes are controls on your form. Assuming yours are called CheckBox1, CheckBox2, etc., you can usesomething like:

Code:
For a = 1 to 30
    If Me.Controls("CheckBox" & a).Value = True Then
Code:
' Do what you want here
Code:
    End If
Next

If they have more varied names then you can loop through all the controls and, for each that is a checkbox, do whatever you want. Post back if code for that would help.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top