Solved

CheckBox Not Recognized as True When Checked

Posted on 2016-11-01
3
38 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

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 22

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

756 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