Solved

MS Access - unable to assign value to a global variable

Posted on 2010-11-28
4
475 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
[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
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 85

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

705 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