Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Constant Question

Status
Not open for further replies.

etrain

Programmer
Aug 3, 2001
65
US
I am wanting to set a Constant through out my database so any and all forms can reference it by just using the Constant name. The one conveant is that is really is not a constant. It is more of a variable. Here is an example, it goes in line with the security question posted previously.

Here is what I want to do:
Const WrkGrp as Long = Forms!frmWhosLoggedOn!lngWrkGrp
Const UserID as Long = Forms!frmWhosLoggedOn!lngUserID
Const txtUserName as Text = Forms!frmWhosLoggedOn!txtUserName

These are all constants in the sense it is the same while the one user is logged on. If another user logs on it changes but while they are logged on it is the same. I can use Dim in the Declarations but I have to set the Variable in the Sub or Function, it can't be set in the General Declarations. This is what I am wanting to avoid.

Questions are what is a way of doing this? How can I do this as a Global Application thing rather than having to declare these variables and setting these variables for every form?

Thanks

Remember the Past, Plan for the Future, yet Live in the Now for tomorrow may never come.
-etrain
 
Hi!

To make a constant global, set it in a Module and use the keyword Public. What's wrong with just accessing the information from the hidden form? It seems more efficient.

hth
Jeff Bridgham
bridgham@purdue.edu
 
I had already tried what you suggest, I believe. I placed this in a module;

Public WrkGrp As Long
WrkGrp = Forms!frmWHOSLOGON!lngCurrentWrkGroupID

This is what you meant right?

When I compile I get an "Invalid Outside Procedure." From what I read it is because (Forms!frmWHOSLOGON!lngCurrentWrkGroupID) is not a constant but a variable. I placed this in the Form's module as well as a stand-alone module but same error occurs.

As far as the other question. It does work pretty well I just was wondering if anyone had any other thoughts about it.

Thanks for responding.
Remember the Past, Plan for the Future, yet Live in the Now for tomorrow may never come.
-etrain
 
Hi again!

Put the following line in a Public Function:

WrkGrp = Forms!frmWHOSLOGON!lngCurrentWrkGroupID

As well as any other line you use to put a value in your variable. You will be able to call the function from anywhere in your database and can even call it from the autoexec macro using the RunCode action.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Ok so I added this to my basSecurityCheck module;
In the General Declaration I added
Public Public WrkGrp As Long
I then added a new function:

Public Function fnWrkGrp()
fnWrkGrp = Forms!frmWHOSLOGON!lngCurrentWrkGroupID
End Function


Within the form I want to check the WrkGrp I add something like;

If fnWrkGrp >= 20 Then
Me.cmdAddDocuments.Enabled = True
Else
Me.cmdAddDocuments.Enabled = False
End If


It seems to work as planned. Is this along the line of where you were going with it?
Remember the Past, Plan for the Future, yet Live in the Now for tomorrow may never come.
-etrain
 
Hi!

Well that wasn't what I was thinking, but it looks like what I should have been thinking!

:)
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top