A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Public Variables



 
 
Thread Tools Display Modes
  #1  
Old February 23rd, 2006, 01:26 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Public Variables

Hi

I store the company name that is displayed on all my forms in a table. I use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre


Ads
  #2  
Old February 23rd, 2006, 04:44 PM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Public Variables

you would declare the variable in a standard module (not a form or report
module), and put it at the top of the module, directly after the Option
Compare and Option Explicit statements.

you would have to set the value of the variable in code. you can do this in
any event procedure. suggest you use the Open or Load event of the first
form that opens when the database is opened. or you can write a public
function in a standard module to set the value of the variable, and run the
function from an AutoExec macro, which will automatically run when the
database opens.

on each form's Load event, you would add code to set the value of the
textbox control that displays the company name, as

Me!TextboxName = GlobalVariableName

as for which one is better: unless you have a whole lot of records in your
CompanyDetails table and/or are experiencing a noticeable lag in getting the
company name control populated when the form opens, i probably wouldn't
bother with all of the above, and would just use the DLookUp().

hth


"Pierre de Beer" wrote in message
...
Hi

I store the company name that is displayed on all my forms in a table. I

use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value

assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre




  #3  
Old February 24th, 2006, 01:38 AM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Public Variables

Your use of the value in a table is actually the preferred method.

Global variables are somewhat risky. In the example you give probably
not much risk at all. The risk is that a global variable can be
modified anywhere in your code. From the depths of your code you
don't always know how program execution got to the current line. Many
a frustrating hour and day has been frittered away by people chasing
problems caused by global variables. Somewhere else in your code the
variable is assumed to have a value that reflects a certain state of
affairs. Other code was written with other assumptions.

The consequences are right up there with failing to require definition
of variables before their use. In those cases, a typing error will
quietly create a new variable for you.

HTH
--
-Larry-
--

"Pierre de Beer" wrote in message
...
Hi

I store the company name that is displayed on all my forms in a

table. I use
DLookup("[Company Name]", " Company Details") to retrieve the

company name
from this table. Is it not better to retrieve the company name at

startup
and store it to a global variable?

If the variable option is the best, how do I declare a global

variable in
Access? I declare the variable in a module but can not get a value

assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre




  #4  
Old February 24th, 2006, 04:26 AM posted to microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Public Variables


"Pierre de Beer" wrote in message
...
Hi

I store the company name that is displayed on all my forms in a table. I

use
DLookup("[Company Name]", " Company Details") to retrieve the company name
from this table. Is it not better to retrieve the company name at startup
and store it to a global variable?

If the variable option is the best, how do I declare a global variable in
Access? I declare the variable in a module but can not get a value

assigned
to it.

As you can see I am new at this.

Kind Regards

Pierre



From what you describe, that sounds like a good candidate for a public
constant.

At the top of a module (not a form or report module):

Public Const CompanyName As String = "My Company Name"

I use this technique for version information that I want to appear on all of
my forms. Just change it in one place when necessary.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
determine if Excel is open geebee General Discussion 11 January 20th, 2006 09:25 PM
Attaching Code DS General Discussion 2 August 22nd, 2005 11:21 PM
Report will not access public variables from form Lee Setting Up & Running Reports 4 May 5th, 2005 04:51 PM
Using Public Variables in my Query Joy Running & Setting Up Queries 4 March 19th, 2005 10:44 PM
Public variables: MSA 2003 GB via AccessMonster.com Setting Up & Running Reports 6 January 23rd, 2005 10:29 PM


All times are GMT +1. The time now is 02:40 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 OfficeFrustration.
The comments are property of their posters.