Using MS Access/User Login/Password help


Hey Mr. Rost,

My level of expertise is in the ballpark of intermediate and advanced using Access 2010.

My immediate question is: How to make a user login/password macro or VBA code.

I have a user table along with a query that lists all users with their appropriate password.  The query has [Login ID], [Login Name], [Password].  I tried using an IF statement with a DLOOKUP code but seems its not working.  Suggestions?

This is not a quick question to answer. I spend about half an hour explaining how to do this in my Access Security Seminar, but logging on is just the tip of the iceberg. You then have to be able to control what your users can and cannot do in the database... and that's the really hard part. The rest of the seminar talks about that in detail.

You're on the right track, though. A DLOOKUP statement is the way to go to verify their credentials. Set up a form with Username and Password fields. In the button code, you can say:

PasswordLookup = DLOOKUP("Password","UserTable","Username=""" & Username & """")
If Password = PasswordLookup then
  Msgbox "Correct"
  Msgbox "Incorrect"
end if

And then you can, of course, direct them to the appropriate Main Menu or other form. Like I said, though, this is just the beginning. Now you have to know how to keep users out of your Navigation Pane, other forms, tables, your VB code, etc. Smart ones will know how to bypass your startup form, attach another database to your tables, etc. My seminar shows how to lock all of that down.

Using MS Access

All Answers

Answers by Expert:

Ask Experts


Richard Rost


I am happy to answer any kinds of questions about Microsoft Access - from basic table design to advanced VBA programming. Also, please feel free to check the Access Tips & Tricks section of my web site, and free Access 101 tutorial.


I am the president of and I specialize in Microsoft Access Tutorials. I have been teaching Access in the classroom since 1994, and online since 2002.

I am a self-taught Access expert. I have been building databases for clients since the early 90s. You can see a sample of my Access Tutorials on my web site at

©2016 All rights reserved.