use a variable with .value??

owen

New member
Local time
Today, 21:11
Joined
Feb 28, 2009
Messages
8
Excuse my ignorance I am a newbie to vba and attempting to learn as I code..

Have a form with multiple checkboxes with names from chk11 .. chk 57 where the first digit represents a day and the second digit represents a 'session'. In my code, I want to loop through each session within each day and if the checkbox is true then to do something else.
I would put some code here but I've tried so many things that is a complete mess..
The latest thing I've tried is to use the checkbox name, eg chk11, as a variable with a .value to find if this is true or not - presume I can only use .value with a field name and not a variable..
Been going round and round in multiple circles, getting very dizzy and starting to really confuse myself..
Please help..
 
Owen,

You don't need the .Value

If Me.chk11 Then ...

or

If Me.chk11 = -1 Then ...

Both of the above will check to see if the checkbox is True (checked).

Wayne
 
Thanks for that. I've been using a variable though to get the checkbox name because the digits vary to save hardcoding each name.
Here's a bit of the code:

strCheckboxName = "chk" & intDaySubst & intSessSubst
testname = Me.strCheckboxName
strchkbox = Nz(testname, False)

was doing the last bit to get rid of null values but it won't get that far.

I can't use a variable name with 'me' - have tried concatting too. Is it not possible to do it?
 
Hi,

You may refer to the control's properties with

Code:
Me.Controls(strCheckboxName).PropertyName
 
woohoo just tried this and it works! - thanks. Didn't realise there was a controls collection - learn something new every day..
 

Users who are viewing this thread

Back
Top Bottom