Constants in Access 2000 VBA

Moonshine

Registered User.
Local time
Today, 18:08
Joined
Jan 29, 2003
Messages
125
Yes, its that time again im back to programming in VBA for a new project im doing at work...

The short description is: I have a database that is accsessed by 6 people, i had changed the front end of the database so that you have to login in with the NT user name we have here at work. It all works fine, login/password depending on what level Access you have, will depend on what you can access when someone helps me

I need to be able to set the persons login name and Security level as a Constant throughout the program once the login form has been closed, for the moment i have gotton round it by one you type in you username and password, then click ok it just sets the login form to visible = false (so the form is still there, and you can just relate back to that and get the value of the field in Text0(user) and Text2(Level).

I dont want it this way, i cant for the life of me find where id set the username (8 character's) and Security level (number between 1 and 5) as a constant.

Please help
 
First things first - you can't set such a thing as a constant. A constant is a value that will never change such as Pi.

Yours will change as you say that you have 6 users and need this variable to store their details rather than hide the form.

Consider using a public variable (declared in a module) and you can assign the username to this variable as the login form closes.
 
Ahh sorry, i thought it was a constant, my knowledge of this is a little vague so the terminology was wrong :)

Ok, sounds like as you say i need to declare a public variable, but everytime i have tried this when the "frm logon" closes, the variable does not stick and i cant call it using VBA in any other form :(

Do you have a sample piece of code or explanation as to how it works?
 
Create a module:

In this module declare this:


Code:
Public strUserName as String
Public intSecurity as Integer


On you Login form's OK button's OnClick event
you can then put this code

Code:
strUserName = Text0
intSecurity = Text2

This will store the variables for use within the rest of your program.

I have noticed in the past that variables declared in modules aren't dimensioned unless the database runs automatically (don't know why!) so, if you haven't done so already, create a macro that opens your login form, and name it autoexec.
 
Hi, and thanks for that :)

Does the module i create need to be called anything in particular? Or will any name do?

And also... if i create a macro, i take it i dont need a form to open up in the "Startup" option?

Scott
 
Ok, ignore that last message. I Just saved the module as mod Secuirty and it works fine :)

I already had a macro called "autoexec" as that runs a piece of code that disables the program X button (you cannot exit out of Access without click a button on my form).

So i guess it does store the variables there :)

But, how do i now use that variable? I have lost my notes on how to call it :(
 
You don't need to "Call" it, it's not a function or routine.

Just use it as you would a normal variable - it's just public, meaning that it can be used throughout the whole database rather than specifically within one form or routine.
 
Thank you!!

Works perfectly now :)))))))))))))))))))))))))
 

Users who are viewing this thread

Back
Top Bottom