Current User Variable (1 Viewer)

fenhow

Registered User.
Local time
Today, 08:28
Joined
Jul 21, 2004
Messages
599
Hi, I have been searching with no luck. I have a simple log in form that uses a UserTable for users and passwords. I simply want to capture the current logged in username (from the log in form) not the computer and call it when I need it, say to update a field "by" when the user makes a change to that record..

I have looked at declaring variables etc but they all point or instruct to the Windows User not my logged in user..

Any help would be appreciated.
Fen
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:28
Joined
Aug 30, 2003
Messages
36,131
Options include saving the user to a public variable during login or hiding rather than closing the login form, thus being able to refer to the control containing the user. I typically do the second, or save the value to a hidden textbox on a main menu form that remains open.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:28
Joined
Feb 19, 2013
Messages
16,601
declare a public variable in a module e.g.

Public CurrentUser as String

and in that module have a public function to get the name which can be used in a query e.g.


Public Function UpdatedBy() as string
UpdatedBy=CurrentUser
End Function

During your login process assign the username to LoggedInUser

CurrentUser=me.username

Then in a query just use the function e.g.

INSERT INTO aTable (fld1,fld2,UpdateUser) VALUES(val1, val2, UpdatedBy)
 

Grumm

Registered User.
Local time
Today, 17:28
Joined
Oct 9, 2015
Messages
395
I would suggest using TempVars.

Problem with global variables is that if you catch errors in your program (and you should do that also), most of the time that global variable is reset and you lose the value that was stored in it. Tempvars can be used as long as the application runs.
(I found this the hard way by using a public variable to store the language of the user. After a while the language was reset and i couldn't figure why... until google found me tempvars :) )
 

Users who are viewing this thread

Top Bottom