Solved

MS Access - unable to assign value to a global variable

Posted on 2010-11-28
4
455 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
ID: 34225031
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
ID: 34225065
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
ID: 34225253
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
ID: 34227720
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

813 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

10 Experts available now in Live!

Get 1:1 Help Now