Access version of Session Variables ????

mikebaldam

Registered User.
Local time
Today, 04:23
Joined
Oct 29, 2002
Messages
114
ok, I have my own logon form (working fine no probs)
but how can I store the current user to pull into forms automatically at a later stage....?

is there session variables in Access (ASP style)...?

I've found other help files that are similar but I cant get them to work - Do you have to set up a new module?


Please help...... :(

Cheers

Mike
________
jugallette
 
Last edited:
For Session type variables, you will need to set up a Global Public Variable or a Property.

You can have this Global variable on a form, but the form will need to always be open to be able to access it. (You will need the formname and variable name).

The easiest method is to create a Module with you Public Global Variables.
 
Ok..... Trying to set up my Variable

heres what got so far..............
-----------------------------------------------------
Option Compare Database
Dim PstrUserName As String

Public Property Get UserName() As Variant
GetUserName = PstrUserName
End Property

Public Property Let UserName(ByVal vNewValue As Variant)
LetPstrUserName = vNewValue
End Property
-----------------------------------------------------
but I cant seem to be able to pull in my UserName into any Forms or Queries.......?

I'm not sure how to do these modules or Global Public Variables
so this is mainly sussed from all the info in here.

Please....someone help put me out of my misery......!!!
________
Ducati 125 Turismo
 
Last edited:
As far as I know, Property Get and Property Let are typically used only in class modules, so if yours is a standard module, that may be part of the problem.

In any case, if you put the following code in a standard module, you should be able to set or retrieve the variable value from anywhere in your application.

Option Compare Database
Dim PstrUserName As String

Function SetUser(UserName As String) As String
PstrUserName = UserName
End Function

Function GetUser() As String
GetUser = PstrUserName
End Function
 
Calling a stored variable

Err ... How do you call the variable ?

I want to be able to update a field in a record with userid when they click a command button?
________
R1200RT
 
Last edited:
I should have indicated SetUser as a sub, not a function, and used the word Public instead of Dim. The corrected code is:

Option Compare Database
Public PstrUserName As String

Sub SetUser(UserName As String)
PstrUserName = UserName
End Sub

Function GetUser() As String
GetUser = PstrUserName
End Function

You can then set the user name with:

SetUser(txtSomeTextFieldOrStringVariable)

and retrieve it as follows:

MyDAORecordSet!MyField = GetUser
or
MyStringVariable = GetUser
or
MyTextBox = GetUser

Of course, the simplest approach is just to do away with the sub and the function, and refer to the public variable (PstrUserName) directly.
 

Users who are viewing this thread

Back
Top Bottom