Checking Checkboxes loop not working

I have a section of code which i must be missing something on.  I have 7 activex checkboxes on a sheet called Datasheets which are grouped together for easy of moving them around.  I would like to run a loop to test their state but I get an error "Object doesnt support this propert or method"  I have tried Me!thischkbox instead but got an "Invalid use error"
For i = 1 To 7
thischkbox = "Checkbox" & i
If Sheets("Datasheet").thischkbox = True Then
 MsgBox ("Checked")    'Code here for when box IS CHECKED
 Else
 MsgBox ("UnChecked")    'Code here for when box IS NOT CHECKED
End If
Next i

Open in new window

LVL 1
simonwaitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

TommySzalapskiCommented:
thischkbox = "Checkbox" & i
It is creating a string that contains "Checkbox1" etc. You can't do what you are trying to do.
You need something like
If Sheets("Datasheet").Shapes(thischkbox).Value = True
0
TommySzalapskiCommented:
The Shapes object lets you index based on strings which is why that works. You can't use strings to reference variable names.
0
TommySzalapskiCommented:
Okay, I didn't test it and it's not quite right. You need this:
If Sheets("Datasheet").OLEObjects(thischkbox).Object.Value = True Then
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

simonwaitAuthor Commented:
Cheers Tommy

That gives.  Unable to get the OLEObjects property of the worksheet class.  As a test I replaced the thischkbox with CheckBox1 but still got the same result
0
TommySzalapskiCommented:
Hmm. It works for me. What version of Excel do you have? How did you create the checkbox? Can you post the spreadsheet?
0
TommySzalapskiCommented:
Does this work? One works for the Forms checkbox and the other for the ActiveX checkbox.
If Sheets("Datasheet").Shapes(thischkbox).Value = lxOn Then
0
TommySzalapskiCommented:
That should be True not xlOn
0
simonwaitAuthor Commented:
I get "Object doesnt support property or method".  I am using Excel 2007.  Created checkbox using the ActiveX control in the developer tab.  So when I click on the 1st checkbox I get a name of CheckBox1 and EMBED("Forms.CheckBox.1","") in the formula bar.

The workbook actually links to a database with login screens and stuff so will try to create an EE version without any sensitive data
0
simonwaitAuthor Commented:
0
simonwaitAuthor Commented:
Sorry forgot to put that the code in question is in the sub read() in the SQL module
0
simonwaitAuthor Commented:
No it isnt its in the Send sub!  Sorry
0
nick-pecoraroCommented:
Try using the .Controls object.

Sheets("Datasheet").Controls(thischkbox)

This should allow you to reference objects by name.

For i = 1 To 7
thischkbox = "Checkbox" & i
If Sheets("Datasheet").Controls(thischkbox) = True Then
 MsgBox ("Checked")    'Code here for when box IS CHECKED
 Else
 MsgBox ("UnChecked")    'Code here for when box IS NOT CHECKED
End If
Next i

Open in new window

0
TommySzalapskiCommented:
I used this code and it worked just fine.
If Sheets("Datasheet").OLEObjects(thischkbox).Object.Value = True Then
Maybe you need to tell it thischkbox is a string? Is it possible you spelled thischkbox wrong when you tested it? Try it like this
If Sheets("Datasheet").OLEObjects("Checkbox" & i).Object.Value = True Then

timesheetTest.xls
0

Experts Exchange Solution brought to you by

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.