473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to create a global variable

167 100+
At a form level I believe I can create a variable as"
Public v_name as string and this variable would be available to all events on the form. (I think!)

I would like to create a 'global' variable that would be available to every form in my access database. How can I do this?

Thanks
Sep 21 '10 #1

✓ answered by Stewart Ross

It's the same principle as that for the form module you mention, except you place the definition in any global code module - one that is available to you from the Modules tab in Access. If there isn't one then you need to add a new one.

If you were to place a variable declaration such as

Expand|Select|Wrap|Line Numbers
  1. Public SomeVar as Long
In a named code public code module you can access its value from any other code module regardless of its scope. I would caution that the use of global variables is frowned upon, as their location is hidden away from their use, and they are accessed without being passed through argument lists to subroutines and functions (by what is known as a 'side effect' in structured programming terms - not a good thing).

Nowadays I tend to use static variables within subs and functions where I would previously have used a global variable. Static variables are locally-defined variables internal to a subroutine or function which retain their values between calls, doing away with the need for side-effect based coding.

-Stewart

2 3883
Stewart Ross
2,545 Expert Mod 2GB
It's the same principle as that for the form module you mention, except you place the definition in any global code module - one that is available to you from the Modules tab in Access. If there isn't one then you need to add a new one.

If you were to place a variable declaration such as

Expand|Select|Wrap|Line Numbers
  1. Public SomeVar as Long
In a named code public code module you can access its value from any other code module regardless of its scope. I would caution that the use of global variables is frowned upon, as their location is hidden away from their use, and they are accessed without being passed through argument lists to subroutines and functions (by what is known as a 'side effect' in structured programming terms - not a good thing).

Nowadays I tend to use static variables within subs and functions where I would previously have used a global variable. Static variables are locally-defined variables internal to a subroutine or function which retain their values between calls, doing away with the need for side-effect based coding.

-Stewart
Sep 21 '10 #2
ncsthbell
167 100+
thanks for the reply and suggestion.. I will take a look at the 'static' variables.
Sep 21 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
24
by: LP | last post by:
After a code review one coworker insisted that global are very dangerous. He didn't really give any solid reasons other than, "performance penalties", "hard to maintain", and "dangerous". I think...
9
by: Newbie | last post by:
Hello, I need to declare a global variable e.g. database connection handle. So that I hava an access to this variable all over my class. How can I do it in c#? Do I have to declare it as static...
7
by: Carlos | last post by:
Ok, I am a VB developer but need to do a C# program, my question is how do I decalre a global variable in c#, in VB.net I juest create a procedure an declare my Variable as Public myVar and I can...
9
by: ruca | last post by:
How can I declare a global variable in my .js file, that I can preserve her value each time I need to call any function of .JS file in my ASP.NET application? Example: var aux=null; function...
3
by: Ralph | last post by:
Hi Is this possible? One thing I can do is create the global array and add the new item to it from inside the function but that's not what I'm looking for. Thank you Ralph
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
14
by: Fred Block | last post by:
Hi All, I'm an experienced VB6 developer and now starting (newbee) with VB 2008 and I'm very excited. Here's an issue I'm experiencing right off the starting line and cannot make sense of it:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.