User name on all forms (1 Viewer)

rzaneil

New member
Local time
Today, 10:23
Joined
Mar 27, 2004
Messages
2
I'm quite new to Access and still struggling very hard on vba programming. I have a db which users have to login through a custom made login form(that I found it through this forum).My questions is, can I display the user name who is logged in at every form they open, for example display their user name in a text box on forms? My db has a table named tblUser with this field:

UserID
UserName
UserPassword
UserlevelID

and Main menu form with other sub menus.

I've searched all the threads but couldn't find what I need. I only found how to capture Network ID/Name or Current User.For your info, i'm not using Access Security.Can anybody help me how to go about that?I'm pleased if anybody can provide the code or examples.

TQ

:)
 

WayneRyan

AWF VIP
Local time
Today, 18:23
Joined
Nov 19, 2002
Messages
7,122
rz,

When the user successfully completes your login form, you have several
options.

Keep the Login form open, but hide it. Then the username is always
available by: Forms![YourLoginForm]![UserName]

You can move the name to your main "switchboard" and reference it in
pretty much the same way.

You can use a Public variable to store it, and reference it by
name, or better yet with a public function: =GetUserName

Your forms can have an "unbound" (no ControlSource) control which
has a default value of one of the above methods.

Access Security is not a trivial topic. It will require quite a bit of
research and preparation to implement. There are quite a few threads
here on this forum.

Wayne
 

pono1

Registered User.
Local time
Today, 10:23
Joined
Jun 23, 2002
Messages
1,186
Create a new standard module and enter code like this into it before saving.

Code:
'Create a User Defined Type.
	Public Type MyUser
	       UserName As String
	       UserLevelID As Variant
	End Type

'Declare a global variable based on the UDT.
	Public UserUDT As MyUser

When you log in the user, fill in the global variable.
Code:
	UserUDT.UserName = "Harcourt Fenton Mudd"
	UserLevelID.UserLevelID = 33

When you open any form, use the form's load or open event to grab the user name using the UDT.

Code:
	Me.Caption = "Welcome " & UserUDT.UserName

Or you can do any of those other things Wayne mentions...

Regards,
Tim
 
Last edited:

rzaneil

New member
Local time
Today, 10:23
Joined
Mar 27, 2004
Messages
2
pono1 said:
Create a new standard module and enter code like this into it before saving.

Code:
'Create a User Defined Type.
	Public Type MyUser
	       UserName As String
	       UserLevelID As Variant
	End Type

'Declare a global variable based on the UDT.
	Public UserUDT As MyUser

When you log in the user, fill in the global variable.
Code:
	UserUDT.UserName = "Harcourt Fenton Mudd"
	UserLevelID.UserLevelID = 33

When you open any form, use the form's load or open event to grab the user name using the UDT.

Code:
	Me.Caption = "Welcome " & UserUDT.UserName

Or you can do any of those other things Wayne mentions...

Regards,
Tim

I' ve made the module you said but I get stucked when coming to the second part of the code: How to fill the global variable using your given code? Can you explain me further/detail(or should I say step by step..), and if you don't mind an example. You know I'm quite confuse when coming to VB or module.Your kind help is much appreciated. For your info I've tried Wayne's suggestion and it work(Thanks Wayne!),but I'd like to learn more with modules and VBA.

rzaneil
 

Mile-O

Back once again...
Local time
Today, 18:23
Joined
Dec 10, 2002
Messages
11,316
Or, make a table:

tblUsers
UserID
Forename
Surname
SystemCode

Then a query (qryCurrentUser)

SELECT Forename & " " & Surname AS User
FROM tblUsers
WHERE Forename & " " Surname = Environ("username");

Then on the form, in an unbound textbox's ControlSource:

=DLookup("User", "qryCurrentUser")
 

pat_nospam

Registered User.
Local time
Today, 18:23
Joined
Oct 14, 2003
Messages
151
I'm using the following in my public module:

Code:
Public Type UserInfo
    ViewID As Integer
    AccessID As Integer
    Active As Boolean
    Password As String
    UserID As String
    SecurityID As String
End Type

Public User As UserInfo

But it behaves very strangely. Sometimes I can pull a variable via User.AccessID, but othertimes I can't.

Mile -- Any suggestions on how to refresh the variable on a given form? Should I just run a query on every form to refresh the variable or what other methods work to refresh a global variable?

I thought though, that by setting the above and populating it initially, that it would remain set until the user logged out or closed the system.

Thanks for the pointers,

Pat
 

Mile-O

Back once again...
Local time
Today, 18:23
Joined
Dec 10, 2002
Messages
11,316
pat_nospam said:
I thought though, that by setting the above and populating it initially, that it would remain set until the user logged out or closed the system.

Without any error trapping in your database, any error that's triggered will cause the loss of any values held in variables.
 
T

Torciec

Guest
I still have problem with it. I am totaly new to Access and i need your help. I have to make my DB to put login in one of the boxes in my form. I was trying to hide login form but i couldnt do it. After day of trying I couldny do it in the other way you said I can do it. Could u help me step by step how to make my DB recieve login from LogOn form in my own form.
Thank you in adwance.
 

Users who are viewing this thread

Top Bottom