Solved

CheckBox Not Recognized as True When Checked

Posted on 2016-11-01
3
34 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stop word moving down 2 62
Saving document in Word 2007/2010 format using MS Word 2013 6 50
MS Word Office 365 Mail Merge 2 60
Word and Excel 2013 - Disabled Items List 3 53
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…
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 shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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…

805 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