Global variable

  • Thread starter Thread starter Jenny Kurniawan
  • Start date Start date
J

Jenny Kurniawan

Hi -

I have coded a login screen where my users have to enter their
userid and password before they can use database.

To enable me to make references as to which user makes a particular
change (i.e. add, delete, update) to a particular table, I would like to
record
the username when the user makes an update.

How do I incorporate a GLOBAL variable for USERID?

Sample table:
Record_ID Date_Entered Date_Modified Modified_BY
14353 8/1/2003 9/8/2003 J_KURNIA

I would like to update the field "Modified_BY" based on the USERID
that the user enters on the login screen.

Any help is greatly appreciated.

Thanks,
Jenny
 
You will have to decide where, and at what point you write out that history
table.

Are you planning a separate history table, or are those sample fields you
have in the main record?

I would assume that you have a well writing application, and thus the users
always update data through forms. since that no doubt is the case, then you
could use the before update event of the form. You would place code like:

if isnull(me.Date_Entered) = true then
me.Date_entered = date()
endif

me.Date_Modified = date()
Modified_By = gblUserName

If you are actually using a history table, then you will need sql in the
before update event.
 
Albert,

How do I declare GLOBAL variable "gblUserName"?

After the user enters UserName and Password, the logon screen will exit.
So, if I declare gblUserName
(DIM gblUserName as STRING), I don't think glbUserName will be recognized in
subsequent forms.


This is the scenario ...
I enter my username as J_KURNIA, and my password on LOGON screen. The LOGON
screen exits after I supply the right password.

I then update an employee's postalcode on EMPLOYEE table. (EMPLOYEE_ID =
15895)
What I want to accomplish is to update MODIFIED_BY field to J_KURNIA. This
will show that J_KURNIA was the last person who modified EMPLOYEE_ID 15895
on EMPLOYEE table.

Before update ....
EMP_ID E_CODE E_POSTAL DATE_ENTERED DATE_MODIFIED
MODIFIED_BY
15895 OSKAR 13605 8/8/2003
NULL NULL

After update ...
EMP_ID E_CODE E_POSTAL DATE_ENTERED DATE_MODIFIED
MODIFIED_BY
15895 OSKAR 99989 8/8/2003
9/8/2003 J_KURNIA

TIA
 
If you are wondering how to define global variables --

If necessary, I usually set up an additional Module named PubVariables.
Then define them as follows:

Public gstrUserID As String
etc.

As long as it is defined as Public and is in a standard Module (Not a Class
Object, i.e. Form or Report) you will have access to the variable throughout
your app.

HTH,
J. Clay
 
Jenny Kurniawan said:
Albert,

How do I declare GLOBAL variable "gblUserName"?

In a standard module (not a forms module), you simply declare the var as
public like:

Public gblUserName as string
After the user enters UserName and Password, the logon screen will exit.
So, if I declare gblUserName
(DIM gblUserName as STRING), I don't think glbUserName will be recognized in
subsequent forms.

Your form will have to "set" the this global var. Note that any un-handled
errors will re-set all of your global vars...so some caution is needed here.
If you deploy a mde file to your users, and un-handled errors will NOT reset
the global vars. So, likely, your users should get mde files.
This is the scenario ...
I enter my username as J_KURNIA, and my password on LOGON screen. The LOGON
screen exits after I supply the right password.

Ok, so when the screen closes, you must set the gblUserName var at that
time. The close event would be ok.
I then update an employee's postalcode on EMPLOYEE table. (EMPLOYEE_ID =
15895)

What I want to accomplish is to update MODIFIED_BY field to J_KURNIA. This
will show that J_KURNIA was the last person who modified EMPLOYEE_ID 15895
on EMPLOYEE table.

Yes, my example code in the forms before update event will work *assuming*
that the above fields are also in the forms bound reocrdset.
 
Back
Top