Login to an Access Application

E

emay

Hi
I want to login to my application I created. I will like my login form to
somehow check my users table to verify the username and password entered
when I click on the submit button. I know what I want but I do not know how
to do it. My Login form is unbound, with unbound labels username and
password and there is a submit buttom. I have set the form properties to
popup and modal.
Can anyone assist?
 
A

Arvin Meyer MVP

Thank you for your help. The application will be running on a single
machine. A Windows password is not even setup on it. How can you
method be implemented. Please, I am not familiar with the backend of
Access so more explaination may be required.

I suggest setting up a password regardless of whether or not you use
security or a password for Access. That way you can control which users are
allowed to do what on the entire machine, not just Access. That way, you can
use a conditional statement like:

If WindowsUserName <> "Arvin" Then
DoCmd.Quit
Else
' run the code
End If
 
E

emay

Hi Arvin,

Will this be the code which will appear behind the submit button.? Will it
be in this format or are ther adjustments to be made? Or is it that I will
no longer need a login form as my approach to security will be general?

Private Sub Form_Click()
'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function


Private Sub Form_Open(Cancel As Integer)
 
A

Arvin Meyer MVP

Put that code in a standard module named something like:

basUtilities

You cannot name a module the same as a function. Then in your query or form
you can check the value like:

Private Sub Form_Open(Cancel As Integer)
Dim x
x = DLookup("SecurityLevel", "tblWindowsUsers", "UserName =" & "'" &
Me.txtUser & "'")
Me.txtLevel = x
End Sub

now txtUser has a controlSource of:

= fOSUserName()

and txtLevel is the security level saved in the table which corresponds to
the permission level I want to give the user. The higher the number, the
greater permissions I give him, and I can always check that level before
opening a form, like on the menu form where all this is saved, on a button
click event I can:

If Me.txtLevel >= 20 Then
DoCmd.OpenForm "frmWhatever"
Else
MsgBox "You have no permissions on this form"
End If
 
K

Keith Wilby

emay said:
Hi
I want to login to my application I created. I will like my login form to
somehow check my users table to verify the username and password entered
when I click on the submit button. I know what I want but I do not know
how
to do it. My Login form is unbound, with unbound labels username and
password and there is a submit buttom. I have set the form properties to
popup and modal.
Can anyone assist?

Can't you just set the database password? No coding required.

Keith.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Eeek! I am forbidden access? 12
login table and login form 8
Users log 4
How to program submit button 7
Login Help! 2
login form 1
Restricting access to database using forms 4
Search form via filter 5

Top