Globals variables. I don't know to do corretly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • messias
    New Member
    • Feb 2015
    • 1

    Globals variables. I don't know to do corretly

    Hello!

    I need to get informations at initialization of database access program, like Institution Name, Address, City and tels, register them in variables (globals) and put them at header of report.
    I don't knowing to do corretly.
    Please anybody can help me?

    Thank

    Messias Ribeiro
    Brazil.
    Last edited by Rabbit; Feb 18 '15, 05:00 AM. Reason: Personal email removed per forum policy
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    A really easy way is to create a Module and put something like this into it:
    Code:
    Option Compare Database
    Option Explicit
    Global Const mVersion = "3.017"
    Public Function getVersion() As String
        getVersion= mVersion 
    End Function
    This creates a Constant and a function to return the value of that Constant. Then in your Report, you can drop a TextBox in the Header and set the ControlSource of the TextBox to something like
    Code:
    =getVersion()
    If you want to get tricky, you can use variables instead of constants:
    Code:
    Option Compare Database
    Option Explicit
    Global gLongAppName As String
    Global gShortAppName As String
    Public Function getLongAppName() As String
        getLongAppName = gLongAppName
    End Function
    Public Function getShortAppName() As Double
        getShortAppName = gShortAppName
    End Function
    Public Function initDatabase() As Boolean
        ' This code is to be run when the database first loads.
        ' Called from an AutoExec Macro, or a Main Menu's OnLoad Event
        gLongAppName = "The Long Name of your Application"
        gShortAppName = "TLNA"
        initDatabase = True
    End Function
    You can get even tricker if you want, by loading the Variables from values stored in a table. I can post an example of that if you need it.

    Comment

    Working...