Solved

CheckBox Not Recognized as True When Checked

Posted on 2016-11-01
3
27 Views
Last Modified: 2016-11-01
Can someone tell me why these check boxes don't work?  The macro does not seem to recognize when a check box is True?  It immediately goes to the Else condition.  This series of macros starts with the Begin macro.
Grocery-List-.doc
0
Comment
Question by:cowboywm
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Ejgil Hedegaard earned 500 total points
ID: 41869176
BagelsCheckBox in the module is not connected to BagelsCheckBox on the userform.
It has the same name, but is another variable.

Add the userform name and it will work.
If GroceryListUserForm.BagelsCheckBox = True Then

Best to force variable declaration with Option Explicit, and you will see it when compiling.
0
 

Author Closing Comment

by:cowboywm
ID: 41869245
Yes, that did the trick.  I suppose there were too many pages on the form causing the need to expressly referring to the user form.
0
 
LVL 21

Expert Comment

by:Ejgil Hedegaard
ID: 41869296
That is not the reason.
You can have the same variable name in different subs or forms.
Each refer only to the sub they are in, unless directly specified otherwise.

That is why I suggest you use Option Explicit at the top of each module (or form) so that all variable must be declared.
Then when compiling, the not specified names will be found before runtime.
It makes coding easier, type the beginning of the name, and press Ctrl+Space, and you will get a list of possible names to use, or if only one, VBA will insert the name.
And typing errors will not result in another variable.
0

Featured Post

A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now