Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CheckBox Not Recognized as True When Checked

Posted on 2016-11-01
3
Medium Priority
?
53 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 23

Accepted Solution

by:
Ejgil Hedegaard earned 2000 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 23

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses

636 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