Академический Документы
Профессиональный Документы
Культура Документы
Before creating a Login Form, you need to set up a user table that can verify the login ID and password on the
Login Form. The step of creating Login Form can be followed below:
Create a table tblSecurity with a SecurityID and SecurityLevel field and add admin for SecurityID =1 and user for
SecurityID =2
Create a table tblUser with a UserName, UserLogin, UserSecurity and UserPassword fields. Remember to add an
input mask on the password field so that passwords are not blatantly visible in the table.
Latest Blog Posts
I choose to display the type of user rather than just the raw number of the User’s security level by using the
Lookup options in the design view. This way the UserType field is a number corresponding to the User’s security
level because it refers to the SecurityID in the tblSecurity but displays the user’s UserType in text (admin, user
etc.). You can create the UserType field from the Lookup Wizard on the dropdown of Data Type column.
accesshosting.com/create-login-form-ms-access 1/13
4/11/2019 How to Create a Login Form for MS Access
Create a Login Form from the Dialog form design. Then customize the form to your liking.
Create two text boxes in the Login Form as txtUserName with label Login Name and txtPassword with label
Password
Under the “On Click Event” of the Cancel button, add the Embedded Macro with a QuitAccess command to exit the
program or Access application
accesshosting.com/create-login-form-ms-access 2/13
4/11/2019 How to Create a Login Form for MS Access
Create a Navigation and Admin Form area to reroute your users to the appropriate area of your database
application.
Under On Click Event of the OK button, add the VBA code below under the Event Procedure
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName", vbInformation, "Username required"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Password required"
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And User
MsgBox "Invalid Username or Password!"
Else
TempID = Me.txtUserName.Value
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'"
UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please change Password", vbInformation, "New password required"
DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
Else
'open different form according to user level
If UserLevel = 1 Then ' for admin
DoCmd.OpenForm "Admin Form"
Else
DoCmd.OpenForm "Navigation Form"
End If
End If
accesshosting.com/create-login-form-ms-access 3/13
4/11/2019 How to Create a Login Form for MS Access
End If
End If
End Sub
Set the Login Form to display immediately when the Access Database is opened. Go to File->Options and select
the Current Database option from the list. Then set the Login Form as the display form.
It should be noted that while this login procedure is helpful to have permissions and different roles withing your
Access database and may be needed for our Remote Desktop Hosting – it is not necessary for any hosted Access
Web App or Sharepoint Application since you can use the Sharepoint user roles and login procedures rather than
handling it within the Access Database itself.
Share this:
Related
Getting Started with an How to create an MS Access The Top 10 Reasons to Split
Access Wep App in 2013 Web App from within an Access database
Sharepoint Sharepoint Enteprise February 25, 2015
July 19, 2016 June 11, 2015 In "Access 2003"
In "Access 2013" In "Access 2013"
This entry was posted in Access 2016, Remote Desktop Hosting, Tutorial and tagged Access 2016, Remote
Desktop, VBA code sample. Bookmark the permalink.
accesshosting.com/create-login-form-ms-access 4/13
4/11/2019 How to Create a Login Form for MS Access
Reply
slelgan says:
This works for the most part, but there is an unexplained form “frmUserinfo” that needs to be created for
it to work with a new user that has “password” for their default. Please add the details for this form.
Reply
faza says:
Reply
Reply
electrifekt says:
How do you link to a new form after login? Complete noob to this.
Reply
Dave says:
Reply
S says:
Getting an error on the line the is Me.txtUserName.SetFocus under the if is null. please help
Reply
lynich says:
Agreed. This is extremely helpful and I’m curious about setting up the “frmUserinfo” and how it correlates
to changing to a new password from their default, too. Any help here would be appreciated.
Reply
accesshosting.com/create-login-form-ms-access 5/13
4/11/2019 How to Create a Login Form for MS Access
Vsm says:
Reply
Tlhogi says:
Can you post a link to your access file with the code?
Reply
Pdiddy says:
Getting an error on the line the is Me.txtUserName.SetFocus under the if is null. please help
Reply
Reply
Melanie says:
This is amazing – would have taken me so long to work out alone! With just a couple of changes I could
adapt it to my already existing DB. Thank you
Reply
idmrentals says:
Do you actually have a control that has the name “txtUserName” ? Also you may want to actually ensure
you have interactively specified the form_load() routine from the correct form you are using. You can do
this by going to the properties of your form and selecting the Event tab on the property sheet. Select on
load. Then go to code builder (not macro builder etc.) (note this applies to Access 2016.)
Reply
idmrentals says:
I think all you have to do is specify the form you want to be directed to. See code: If UserLevel = 1 Then ‘
for admin
DoCmd.OpenForm “Admin Form”
Else
DoCmd.OpenForm “Navigation Form”
End If
So for your application, specify the form you want to open replace “admin form” with the name of your
form or “Navigation Form” with the appropriate form etc.
Reply
accesshosting.com/create-login-form-ms-access 6/13
4/11/2019 How to Create a Login Form for MS Access
idmrentals says:
Do you really need it? meaning just remove the logic that checks the password….if you need that
password check, then yes create the form that will store the new password. In the new form force the
user to change the password – follow the same logic and then direct them to the form they need to
reach….
Reply
S says:
How do a track when users login to the database? I have tried multiple different vba coding
configurations, and they do not work. If you have any insight that would be great.
Reply
S says:
Reply
George A says:
I’m getting same error on the line the is Me.txtUserName.SetFocus under Private Sub Form_Load () and
the Error coming saying method or data member not found. Whomever replied it works, can you post the
VBA code in whole? I did above step by step in new database before adding any company data, and no
joy.
Reply
ZUL says:
Reply
vardis says:
I ve implement the above example and it works perfect. I have 2 questions. 1.Does it work on the web?
2. How do i setup specific users 2 view only their records ? (according 2 username and password they
enter)
Reply
V Kumar says:
I typed the vba code but after ok nothing is happened. File error 2471 can help any please
Reply
accesshosting.com/create-login-form-ms-access 7/13
4/11/2019 How to Create a Login Form for MS Access
Reply
Reply
Brewmaster says:
The Password validation is not case sensitive. Any thoughts on fixing it?
Reply
Brewmaster says:
you have to create the forms. The logic is already there to trigger forms named “Admin Form” and
“Navigation Form”.
Reply
Brewmaster says:
Reply
Lj says:
This works like magic, for the Me.txtuser error, you have to customize the right cell name so the code will
work. Thank you!
Reply
Pongpanod says:
Reply
accesshosting.com/create-login-form-ms-access 8/13
4/11/2019 How to Create a Login Form for MS Access
nemo says:
its working but you can used the password of other users to log in
Reply
d says:
I am getting an error “Ambiguous Name Detected: Command1_Click when opening the form.
Reply
Charles says:
Reply
Les says:
“Create a Navigation and Admin Form area to reroute your users to the appropriate area of your database
application”. what does this part of the guide mean?
Reply
Paul says:
The code works great. My question is how do you get the login screen to open without any login info pre-
filled? Right now it opens right up with the admin login info prefilled. Pretty much defeats the purpose.
Reply
I have noticed a problem that while it does require a password and username, they do no need to match..
I have noticed that as long as the password is in the table, it does not have to be the one associated with
that particular user, it will still provide access. Any ideas why this is?
Reply
Jamila says:
thank you so much it works ,, how to get the username in other form ???
Reply
Mike says:
Reply
accesshosting.com/create-login-form-ms-access 9/13
4/11/2019 How to Create a Login Form for MS Access
Getting an error on the line the is Me.txtUserName.SetFocus under the if is null. please help
Reply
x says:
Reply
db says:
how would I retrieve that username to use on a form to display the current user ?
Reply
Tanya says:
Reply
Rui says:
Reply
Reply
eranka says:
HI
Reply
accesshosting.com/create-login-form-ms-access 10/13
4/11/2019 How to Create a Login Form for MS Access
Houcine says:
Great work!!
Do you have an example of drag and drop files from explorer to listbox
Thank’s in advance
Reply
Chad says:
Reply
I am getting an error “Ambiguous Name Detected: Command10_Click when opening the form.
Reply
Reply
Error saying “method or data member not found” then highlight “Private Sub Form_Load()
Me.txtUserName.SetFocus”… can anyone help me on this please? This is the vba code…
+++++++++++++++++++++++++++++++++++++++++++++
Option Compare Database
If IsNull(Me.txtUserName) Then
MsgBox “Por favor ingrese Nombre de Usuario”, vbInformation, “Nombre de Usuario requerido”
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox “Por favor ingrese su clave”, vbInformation, “Clave requerida”
Me.txtPassword.SetFocus
Else
If (IsNull(DLookup(“UserLogin”, “tblUser”, “UserLogin = ‘” & Me.txtUserName.Value & “‘ And
UserPassword = ‘” & Me.txtPassword.Value & “‘”))) Then
MsgBox “Nombre de usuario o clave inválida!”
Else
TempID = Me.txtUserName.Value
UserName = DLookup(“[UserName]”, “tblUser”, “[UserLogin] = ‘” & Me.txtUserName.Value & “‘”)
UserLevel = DLookup(“[UserType]”, “tblUser”, “[UserLogin] = ‘” & Me.txtUserName.Value & “‘”)
TempPass = DLookup(“[UserPassword]”, “tblUser”, “[UserLogin] = ‘” & Me.txtUserName.Value & “‘”)
UserLogin = DLookup(“[UserLogin]”, “tblUser”, “[UserLogin] = ‘” & Me.txtUserName.Value & “‘”)
DoCmd.Close
If (TempPass = “password”) Then
MsgBox “Por favor cambie su clave”, vbInformation, “Clave nueva requerida”
DoCmd.OpenForm “frmUserinfo”, , , “[UserLogin] = ” & UserLogin
Else
‘open different form according to user level
If UserLevel = 1 Then ‘ for admin
DoCmd.OpenForm “Formulario de navegación”
accesshosting.com/create-login-form-ms-access 11/13
4/11/2019 How to Create a Login Form for MS Access
Else
DoCmd.OpenForm “Formulario de navegación”
End If
End If
End If
End If
End Sub
Reply
Gijsbert says:
To open the form frmUserinfo the filter in above script is not working in Access 2016/Office 365:
DoCmd.OpenForm “frmUserinfo”, , , “[UserLogin] = ” & UserLogin
Replace it with:
DoCmd.OpenForm “frmUserinfo”, , , “[UserLogin] = ‘” & UserLogin & “‘”
It will works like a charm. frmUserinfo will open with the correct user filtered
Reply
Hana says:
Working perfectly…
thanks
Reply
Leave a Reply
accesshosting.com/create-login-form-ms-access 12/13
4/11/2019 How to Create a Login Form for MS Access
About Remote Desktop Hosting SharePoint 2013 Hosting SQL Server 2012 Hosting Sharepoint 2010 Hosting
Windows Dedicated Server Hosting Find the right Hosting Plan Backup Plans Blog MS Access Tips & Tricks Video
Tutorials Contact Free Trials Support Sharepoint Hosting FAQ Remote Desktop FAQ
© 2010-2019 Access Hosting LLC. All Rights Reserved | Sitemap | Privacy Policy | Acceptable Use Policy | Terms of Service
Microsoft ®, SharePoint ®, and Windows ® are all trademarks of Microsoft Corporation
accesshosting.com/create-login-form-ms-access 13/13