passing variables from one form to another

jkmb

New member
Local time
Today, 03:09
Joined
Sep 5, 2012
Messages
7
I am creating a data base for multi user and permission controls. For example, one user has view only permission where as another has read permissions. In the log in form, the user permission is verified before logging into the navigation form. I created different navigation forms for different permission controls.

My problem is how do i pass the variable value that contains the "user id" from the login form to all other forms. By doing this I cud load the corresponding forms for different employees with different permissions.

I am newbie in VBA coding. Coudnot make out a lot from search I made.
 
You can use the OpenArgs portion of the OpenForm method to pass information or instructions from the calling form to the form being opened.

The OpenArgs can then be testes in the On Load event of the form being opened to determine how it should behave under different circumstances.
 
OpenArgs is definitely one way to pass things around... ONE thing, that is.

I noted that you said you are also a beginner, so I would get started that way.

Eventually you will bang into the wall ( :banghead: ) that you need to really pass more than one thing around. When you come to that point, I found that creating global variables (or objects, even more complex and powerful) in VBA was the answer. Global things are simply that... existing in the context of the entire application.

To define such, simply define those variables / objects in the top of a module. That is, outside of and on top of any functions / subroutines. Then you are free to use the variable across you entire application.

Tip: And if you define a variable / object in the similar location of a form, then that variable / object exists in the context of the Form object and will survive as long as the form stays open. Must be at the top of Form code, before the first form event.
 
Even with OpenArgs you can pass complex, and multiple pieces of information/instructions. It's just a matter of developing a method of Concatenating that information so that it can be reliably disassembled in the form being called.
 
I prefer to use a class that is global to the project. The class can be populated in any form that has the information and retrieved by any form that needs the information. No need to develop and copy code for concatenating and disassembling and the class structure enforces correct variable name spelling and helps with remembering variable names since typing the class name followed by a period returns a list of defined members, which can be as simple as data elements or as complicated as functions that may be needed by multiple forms. To keep the class manageable, a projec may need several small classes, each for a specific purpose. User permissions and their rules probably belong in their own class. It's often useful to isolate system settings read in from a config file or gathered at startup in their own class so there's no need for a trip to the server everytime the code needs to check a setting value.
 

Users who are viewing this thread

Back
Top Bottom