Re: Global Constants

From: Albert D. Kallal (kallal_at_msn.com)
Date: 04/23/04


Date: Fri, 23 Apr 2004 14:34:37 -0600

If you declare constants, or any variable in a standard module as
public..then it is available in all code, forms reports.

However, just remember that you can shove, or reference a constant, or
variable value directly in a text box.

If you need to use a variable directly in sql statements, or in a text box,
then you need to wrap the variable in a public function, and then that
public function can be used;

So, I can shove a global variable into a text box with some code like:

forms!Customers!City = gblDefaultCity.

But I can NOT just put glDefaultCity in the text box expression. So, text
box, and for that matter all controls don't allow you to put a variable name
directly in them as the data source. You have to use code to load up the
text box. Those global vars are available in code anywhere in the
application.

However, you can put in a global function name, so, you can go:

=MyGlobalFunctionName()

The global function is placed in a standard module...like

Public Function MyGlobalFunctionName as string

   MyGlobalFunctionName = gblDefaultCity

end function

Note that you can place form expressions anywhere...so often in place of a
few global vars...we create a form, set the values..and then make the form
invisible. This is often preference since any un-handled code executing
error will re-set all of your global vars. (if you make a mde then this is
not the case...and again one great reason why most developers always
distribute a mde in place of a mdb).

--
Albert D. Kallal        (MVP)
Edmonton, Alberta Canada
pleasenonoSpamKallal@msn.com
http://www.attcanada.net/~kallal.msn


Relevant Pages

  • Re: Run a macro that tests for the number of fields in a table
    ... In a standard module, type this: ... Public Function CountFieldsAs Integer ... The reason I'm after this info is I have some raw data that I'm importing into a table in Access. ... So I was trying to automate this by using a macro to test for the number of fields. ...
    (microsoft.public.access.macros)
  • Re: Using an imported code module
    ... I have seen the recommendation to use ... standard module for such things, but am not sure I am implementing it ... Public Function SetCurrentRecordNumber ... the brackets and the error message. ...
    (microsoft.public.access.formscoding)
  • Re: macro vs function
    ... you could create a Public Function in a standard module (say: ... CloseFormAndOpenAnother), pass in the name of the next form, and call ... into the second form, or if you wanted to use the where-clause ...
    (microsoft.public.access.forms)
  • Re: Using an imported code module
    ... standard module for such things, but am not sure I am implementing it ... Public Function SetCurrentRecordNumber ... the brackets and the error message. ... exactly as it appears in the function itself, but that was invalid syntax. ...
    (microsoft.public.access.formscoding)
  • Re: Using an imported code module
    ... standard module for such things, but am not sure I am implementing it ... Public Function SetCurrentRecordNumber ... but the same syntax did not work for ... the brackets and the error message. ...
    (microsoft.public.access.formscoding)