Results 1 to 8 of 8
  1. #1
    mrbabji is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    12

    How to use global/public variable

    Hi




    The only info I know about global variable is Once it is declared,that can be used anywhere in your project. Is it true? Further, how to declare? where to declare? and how to use it is completely blank for me.

    I have a "log on" form from which I will capture the user name into a variable.

    I would like to use that variable in other forms and Basing on which I would like to generate reports on other forms and give permissions for editing etc.


    Request anyone to help me in understanding and using the global variable concept in the above scenario.

    Thanks & Regards
    Nag

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You could leave that form Open, but hidden and still be able to reference controls on the Form

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    What you ask is true.
    I would declare it in a module.
    In the code editor click on the Insert Module icon.
    Double click the new module and declare you variable there.
    Dim variable as whatever

    Note: You can not give the variable a value in the module you opened. That has to be done in a sub or function.

    It will be declared (Dim) when the database opens and should be available to all modules and subs.

    EDIT: Usage is just like any variable, YourVariable = SomeThing.

    Dale

  4. #4
    mrbabji is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    12
    Sorry.

    I Tried with simple two attach a db with simple 2 forms and 1 table. The size is572 KB which is not permitted. I am unable to reduce the file size further.

    Pls help.
    Atleast I will try to elobarate what I need.

    I have a user table, logon form, update form

    Once username and password is fed on log on form. The username should be assigned to the global variable declared and update form shoud open.

    In update form, the updae button should be enabled only if the user name is "admin".

    Hope I am little clear now.

  5. #5
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Select the file in your folder window. Right click and select send to the zip.

    The zip file will upload.

    Dale

  6. #6
    mrbabji is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    12
    Zip file is not accepted for upload

  7. #7
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Did you try the zipped folder or the file?


    Dale

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Since you're running v2003, in deciding how to approach this, you need to be aware that Public (global) variables are reset (i.e. 'zeroed out') if an Unhandled Error occurs anywhere in the app!

    In later versions (2007 forward) something called TempVars was introduced, which eliminated this problem.

    If losing this bit of data won't cause any critical damage, by all means use a Public (Global) Variable, but if it is important, in v2003 you would probably be safer using orange's suggested approach of leaving the logon Form open, but hidden, and referencing the appropriate Control(s).

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Global variable
    By ramdandi in forum Queries
    Replies: 3
    Last Post: 12-18-2011, 01:01 AM
  2. Username as Global Variable
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-10-2011, 10:45 AM
  3. Replies: 4
    Last Post: 07-14-2011, 12:55 PM
  4. How to declare Global Variable
    By ganeshvenkatram in forum Access
    Replies: 1
    Last Post: 06-16-2011, 05:18 AM
  5. Dlookup in query using Global variable
    By newwales in forum Access
    Replies: 1
    Last Post: 06-03-2011, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums