Solved

MS Access - unable to assign value to a global variable

Posted on 2010-11-28
4
449 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
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 …

863 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

22 Experts available now in Live!

Get 1:1 Help Now