Home  Fees/Services  Microsoft Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access VBA Tutorial
   
Access Programming Examples & Code Samples

Visual Basic Global Variables Visual Basic Tutorials, Workarounds & Solutions for VB6
Microsoft Access Global Variables




VBA Tutorials:
Access to Google Earth
VB6 Age Calculation
Change Case VBA
VBA Email via Gmail
VBA Outlook Email
Read Email Access
RTF Report Email
Send Outlook Email Access
Calculate Running Sum
Concatenate Records
VBA Stock Quotes
VBA CreateQueryDef
Database Path Solution
Detail-Master Update
Field Validation VBA
Field Value New-Old
FindFirst Recordset
Get Version Number
VB6 Global Parameters
VBA Global Variables
Labels as Links
List Box Files List
VBA Mail Merge
OutputTo Crosstab
Sort Recordset Trick
VBA Recordset Filters
Reference Form Field
VBA Select Case
Transaction Processing

Visual Basic Function Examples


Global Variables Access Visual Basic

Program-Wide Data Storage Tutorial

Global variables are a powerful feature in Microsoft Access. There are basically two classes these Visual Basic global variables.

  • Local variables defined in a form instance, usually when the form opens.  These variables persist as long as the form remains open. These variables and constants are also known as Public Variables and Public Constants since they are known only to the form and subforms attached to a main form.

    New! Download Access example of Global Variables as Query Parameters
  • Instance-wide variables persist for the duration of the Microsoft Access database session.  These variables, including global constants, are defined in association with a module and become active as soon as the module is called.

Here's an example of the Visual Basic code required to setup public form-level variables in a form:

Access Global Variable

Public gbl_previous_tab As String
Public gbl_username As String
Option Explicit

Private Sub Form_Open(Cancel As Integer)
    ' doing something here
End Sub

As this example show the declaration of a database global variable come right after the 'Option Compare Database' statement and before all declarations of (any) subroutines and functions within the form.

The definition of instance-wide Access global variables is carried out in a module.  The following is the code we use to initialize our Access global variables:

Global Variable Example
' Access global variables definition
Global GBL_Username As String
Global GBL_Previous_Tab As String

Option Explicit

Public Sub Init_Globals()
' Access global variable initialization
    GBL_Username = Environ("username")
    GBL_Previous_Tab = " "
End Sub

Then we make a call to the Init_Globals subroutine in our first-opening form as follows:

Global Variable Example
Option Explicit

Private Sub Form_Open(Cancel As Integer)
    DoCmd.Maximize
    Call Init_Globals
End Sub

As you can see there a lots of things you can keep track with Access global variables.  You can also do some neat tricks - like passing parameters to SQL queries using global variables.

Try our downloadable Access database demonstration of using Global variables as query parameters.

More Global Variable examples:

Global Variables as Query Parameters

Using global variables to pass user selection criteria to queries is a useful programming technique to master. This Access download will provide you with ...
www.blueclaw-db.com/download/global_variables_parameters.htm

Access Database Download: Access Security Alternative

Access Example Download, Download Access Examples Free. Home > Tutorials > Access Example Downloads ... Set global variables. Use the Dlookup function ...
www.blueclaw-db.com/download/access_security_alternative.htm

Access Database Security Alternative

initialize global variables Call set_globals ' Hide tabs Me.TabCtl0.Pages. ... set global access level to failsafe no access then lookup access level ...
www.blueclaw-db.com/microsoft_access_security.htm







Have errors?  No doubt we can answer your question quickly and easily.  Simple questions get simple answers at no charge via email.




Popular Database Templates:

PM/Preventive Maintenance Access Template

Work Order Software

Real Estate Marketing Template Database




Contact Information

VBA runtime tips tricks fix solution

Access Visual Basic/VBA/VBScript/VB6 Tutorials
Visual Basic Error Fix & Problem Solutions