Solved

CheckBox Not Recognized as True When Checked

Posted on 2016-11-01
3
42 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
Paragraph formating? 2 40
Word Personalized Watermarks 5 59
analyze malware in windows document 9 62
Copy one row (from Word) into one cell 14 43
When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
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.

737 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