?
Solved

MS Access - unable to assign value to a global variable

Posted on 2010-11-28
4
Medium Priority
?
481 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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