Solved

MS Access - unable to assign value to a global variable

Posted on 2010-11-28
4
431 Views
Last Modified: 2012-05-10
I have a Boolean variable which I have declared in a standard module, the module name being MGlobal. The name of the variable is gMw. Here is the code in the module:

Option Compare Database

'Globals...
Public gInsert As Boolean
Public gCensus As Integer
Public gWm As Boolean

When assigning a value in a modal popup form the value is not recognized in the forms that follow.

Code in the modal popup:

Private Sub cmdbYes_Click()
        MGlobal.gWn = False
End Sub

Any suggestions?
0
Comment
Question by:jbotts
4 Comments
 
LVL 6

Expert Comment

by:UsamaFoad
Comment Utility
The first thing I saw is the typing error in the name
"Public gWm As Boolean"
"MGlobal.gWn = False"

is the name "gWm" or "gWn"?
0
 

Author Comment

by:jbotts
Comment Utility
The name is gWm. I double checked the code. The error was made when I sent the question.
Thanks
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
You don't really need to refer to it as "mGlobal.gWm". Just do this:

gWm = <Some Value>

Also, understand that Global variables can lose their value if you encounter errors. While there are many devs who use them, there are also a LOT more who do not. In Access, many devs use a hidden form, and include a Textbox on that hidden form to hold the value. You can then refer to it at any time:

Forms("YourHiddenForm").gWm = False

And other forms can get the value:

If Forms("YourHiddenForm").gWm = False Then

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
Also, check the simple stuff.
You may have renamed to Button slightly, so the code you see, may not be on the renamed Object.
;-)
(Remember that, in VBA, if you rename an object, the code will not "Follow" it.)

So open the form in design view, right-click the button and select "Build Event" and make sure you end up on the same event as you posted, else you may have renamed ten button.
In that case simply cut the code from Private Sub cmdbYes_Click() and paste it to the new event/object.

JeffCoachman


0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

12 Experts available now in Live!

Get 1:1 Help Now