We help IT Professionals succeed at work.

Access form for login using active directory

Sivasan
Sivasan asked
on
92 Views
Last Modified: 2017-03-19
Hi all,
I have an access application. I have a login form, in MS Access. Currently, I'm saving the user name, password, security level(User,Admin) and their email , in a table 'Table1' in access table. So when the user opens the login form, he/she enters the user name and password and from that form on clicking the submit button, I authenticate against 'Table1' and redirect to other form, by carrying their name and displaying it on other forms.
Now, I like to get the user name from the domain login ( active directory) on their computer so they don't have to have a separate password for this app and keep entering everytime.

Ideally, when they click Login form I automatically capture their login name from their domain login into the computer and using the 'table1' in access, I can find the security level and direct to other forms, I also like to capture their email from active directory if possible.
I will appreciate if somebody can tell me how I can do that.
Thank you in advance.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Hi Als315,
Thanks you.Does this go on on click event of a button?
I tried to put the code you have provided on a on click event of a button, to see if I can get the user name.It says expected End of Sub.When I add End Sub, it still says End Sub expected.
At least to test, I'm trying to pass the user name from your code to a text box Tbox in my form on a click of event of a button. I would appreciate if you can tell me what I'm missing.
Thanks
CERTIFIED EXPERT

Commented:
It is function, place it to module. In onclick event you can use it as follows:
Dim mail as string
mail = get_mail

Author

Commented:
Hi Als315,
Thanks a millione. Yes, when I did mail = get_mail, now, I can get the email. I'm trying to get the user name as well.Looking at your code, I thought UserName will contain the user name but doesn't display the name.I tried the following.

Private Sub Command0_Click()
Dim mail As String
Dim uname As String
mail = get_mail
uname = UserName
Me.T1 = mail
Me.T2 = uname

End Sub

Wondering if I'm doing it right.
Thanks
CERTIFIED EXPERT

Commented:
uname =  environ("username")

Author

Commented:
Thanks a million for your help