Environ("username") (1 Viewer)

boblarson

Smeghead
Local time
Today, 15:57
Joined
Jan 12, 2001
Messages
32,059
You have to do something like this:

Code:
Dim lngUserID As Long

lngUserID = DlookUp("[UserID]","User","UserName='" & environ("username") & "'")
 

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
Bob: let's try a different approach...

the login form is the startup form. after user logs in then it opens the registration form

what if I have the login form with a drop down box where the user picks his\her name from it and then whatever name is selected there, populates the registration form?

how can I do that?
 

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
halem2,

I'm not sure if I really understood what you want, but here's what it seems to me it's happening with you. (Maybe I'm wrong. If so, discard my reply, OK?) :)

Last year, I created a little DB file with the same login form you've created.

I also had to pass the username value from the login form to other forms and to do this I realized that I couldn't CLOSE the login form after password confirmation.

You said that, after password confirmation, it opens another form and you want to get the username from the login form and put it into a field (combo) in this new form, right? My question for you is: are you closing the login form after password confirmation? If so, it won't work. After password confirmation, you can't close the login form, you have to simply hide it. It will still be opened, but it won't appear on the screen. While it is opened, the other form can get the value from the username field from the login form. But if you close the login form, you lose that link.

Hiding the login form was the way I found to keep the link between its username field and other forms which also have username fields related to each other.

This way, that DLookUp function should work fine.

To hide the login form, use this code after the password confirmation code:

Code:
Me.Visible = False

Remember to turn it back to TRUE and also close it when you close the second form or the DB file, for example.

I hope this could help. :)

Hugs,

Bruce
 

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
You just described my exact situation.

ok... I tried that and I'm still getting an error on the dlookup. Can you post your dlookup so I could look at it?

thanks a million
 
Last edited:

boblarson

Smeghead
Local time
Today, 15:57
Joined
Jan 12, 2001
Messages
32,059
Here's a database I'm currently working on for work (there's no data, at least no real data) so there isn't anything to worry about there. I implemented a login which opens a form based on a user's security level. There are three levels, admin, read/write and read-only. I haven't fully implemented it yet, but if you look you will see that I use the dlookup in the log in form.

To log in you can use admin (password of 54321) or read/write (pwd - 22222), read-only (which gives fewer tabs on the form - pwd of 11111).

There's a LOT left to be implemented in this, so it's nowhere near finished, but it will at least give you some ideas, hopefully.
 

Attachments

  • Transitions2.zip
    280.5 KB · Views: 110

boblarson

Smeghead
Local time
Today, 15:57
Joined
Jan 12, 2001
Messages
32,059
Oh, and I'll just say that I am storing the current login and security level in a table, but I will be using an MDE file with Access Runtime so I won't have any trouble with people getting into the tables.
 

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
thanks Bob. Let me look at your work to see if I can make mine work.

Thanks again to all for all the help.
 

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
halem2,

Take a look at this file I've created for you. :)

I hope it can help you. Don't forget to create security levels for the users (if you need it, of course).

Hugs,

Bruce
 

Attachments

  • login.zip
    19.4 KB · Views: 106

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
Very simple and useful. And you are absolutely right (red text in form). I have been using Access for about 6 months and I am really trying to learn.

thank God for this site and people like you.

thanks to all
 

Simon_MT

Registered User.
Local time
Today, 23:57
Joined
Feb 26, 2007
Messages
2,176
You could simply hide you login form and reference Forms![Login]![User] or
if you have a Menu based system forget the Login form and set the user details onto the Main Menu: user = environ("username"). I acually have a table of employees and use Initials throughout the database and have the username of the Employees run a query in VBA abd set the User on the Menu to the Initials and Employee = Forms![Menu]![User].

If know who the users is anyway do you need to ask again?
 

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
Simon MT,

I agree with you. If the DB gets the username from Windows, there's no need to ask who is going to use the DB. On the other hand, password is important anyway.

Without password confirmation, anyone else can use the computer and mess with the DB.

With password confirmation, only the real user is able to use the DB because he's the only one who knows the password (theoretically).

Cheers! :)

Bruce
 

Simon_MT

Registered User.
Local time
Today, 23:57
Joined
Feb 26, 2007
Messages
2,176
I agree with that it is rather lax not asking for a password, but having given each user the database within their user profile i.e. the Client Front End you have already given them the OK to use it. One way, I get around who messed up is uneditable the Employee tagging so you can't change them.

It is very difficult to fully eliminate malicious damage to any system by internal users, however you can mitigate the damage by regular backups and intruder protection. The other factor is if users consider that a system has value and makes their life easier then what you have designed and laboured over; has respect.
 

boblarson

Smeghead
Local time
Today, 15:57
Joined
Jan 12, 2001
Messages
32,059
In my sample that I uploaded, I could capture the user's login name and then force a password, which normally I would do, but in my case the users will be using the database from a single computer login, but will need to change between each other to track who is doing what and also to grant different permissions. There will be some users who have admin level access (can change lists, etc., some who have read/write access who can add and edit sales, and some with read-only access so they can only do things like read reports. So, in my case both a username and password are necessary and I can't just give all access based on computer login.

So, they may not need that level of access, but it isn't always as simple as capture the user name and give unlimited access to everything.
 

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
new challenge..

I'm using the code from Brunces on page 2 and it works great. I added an unbound control to the frmLogin and called it UserLevel. I also added a new field to the tblUser called UserLevel

I need to fill the UserLevel control on the frmLogin with the value of the user level depending on the user

this dlookup does not even give an error...Can anyone tell me what I'm doing wrong?

Me.UserLevel.Value = DLookup("UserLevel", "tblUsers", "UserUser = '" & Me.LoginUser.Value & "'")

by the way, the reason why I need to do this is to open a different form depending on the UserLevel.

thanks
 

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
halem2,

Hi, buddy. Sorry, I hadn't seen the message you sent me. :)

Take a look at this file. Hope it helps you. :)

Hugs,

Bruce
 

Attachments

  • login2.zip
    20.1 KB · Views: 97

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
halem2,

I've been thinking about your login... The user Admin can access any of those two forms, right? Admin is always "the man". (lol) So, that would be nice if you had a special level name for Admin and give him the option to choose what form to open. Maybe you should have a special menu for Admin, with links to everything he can access. What do you think? :)

Take a look at this file. (Choose user Admin and test it.)

Hugs,

Bruce
 

Attachments

  • login3.zip
    24.3 KB · Views: 104

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
halem2,

I forgot to say... In your unbound control (TextBox), you should use it this way...

=DLookup("[UserLevel]";"tblUsers";"[UserUser] = '" & [LoginUser] & "'")

No need of VBA here. Just put this formula above inside a TextBox.

Obs.: My MSOffice is in Portuguese and some functions use ";" instead of ",". Try both over there and see which fits better to you. :)

Hugs,

Bruce
 

halem2

Registered User.
Local time
Today, 18:57
Joined
Nov 8, 2006
Messages
180
Brunces you are awesome! I would buy you a beer if you lived here! Thanks man you are awesome.
 

brunces

Registered User.
Local time
Today, 19:57
Joined
Sep 12, 2004
Messages
45
You're welcome, halem2. I'm glad I could help you. :)
 

Users who are viewing this thread

Top Bottom