Checkboxes & VBA

This one is quite interesting. This could be something very trivial, but I would like to share this information.

I added a Checkbox on a Smartlist lookup using Modifier. Two functionalities with respect to this new checkbox:

1. This option should be selected by Default when we open the lookup.
2. Based on this value (selected/de-selected), the records should be refilled on the scrolling grid.

I was able to achieve the second one, by adding my code inside the validation in VBA:

If <WindowName>.<Checkbox>.Value = True Then
{My Code}
{My Code}
End if

But for the first one, I tried the statement:

<WindowName>.<CheckBox>.Value = True

This never worked. I was quite confused, since the same statement worked on a validation but NOT WORKED on assignment. I checked back the VBA Manual and found that, for checkboxes we need to use either a number 1 (Select) or number 0 (De-select). So ideally, my statement should have been:

<WindowName>.<CheckBox>.Value = 1

Well, that did the trick and below is the conclusion:

To check whether a Checkbox is selected or not, you can write a code to check whether the value of that Checkbox is TRUE or FALSE. But, to select or de-select a Checkbox programmatically, you must assign either a number 1 or a number 0.



One thought on “Checkboxes & VBA

  1. i am new in vba program, so that i want to know how we can set the error if all of three checkbox not checked. and if checkbox checked morethan one checked. anyone please help me…..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s