How to Password Protect a Form or Report in Microsoft Access

How to Password Protect a Form or Report in Access

by Shane Zentz
Microsoft makes doing a lot of things with databases very easy. And password protecting a form or report is no exception. With just a few lines of code in the right place you can prevent unwanted users from opening and viewing or editing data in your form or report. Just as an aside, this is not the most secure method and in fact is not really secure at all. But in order for someone to find the password (which is hard-coded into the application) they would have to have at least basic knowledge of access from the design and programming point of view, so if they are just users then chances are that they will never discover the password (by looking at the code behind the program) unless someone tells it to them or they discover it written down somewhere. Having said that, this method is still pretty useful for just average applications, like I said it is not really the most secure method, so if your application contains really sensitive data (like social security numbers or bank account numbers) then I would advise using another more secure method. But if you just need a basic password protection to protect just one or a few forms from average users then this method will work and it is also quick and very easy. So read on to see how this is done.

Open the form or report that you want to password protect in design view and find ‘form’ in the properties field (see photo 1). Then switch to the events tab. Under the events tab you will see a field called ‘on load’ (see photo 1), this is the field that controls what the form or report does when it is first loaded or opened. Here we want to add some code to the on load event so that it will first prompt the user for a password. So click on the tiny icon with the three little dots on it and on the window that pops up, select ‘code builder’. This will bring up a Visual Basic window (see photo 2) which will have a method for the ‘onload’ event preloaded. All we need to do is to add the code to this section.

 

Here is the code:
Dim PassWord As String

PassWord = InputBox(“Enter Password”)

If PassWord = “whatever password you choose here” Then’

Open FormDoCmd.OpenForm “name of the form that you want to password protect”
ElseMsgBox (“Wrong Password?”)

DoCmd.Close acForm, Me.NameEnd If

Save the code and exit and also save the changes to the form. Now try to open the form and you will get a password box before the form will open. If you enter the correct password then it will open, otherwise it will not. Another thing I should mention is that the text for the password is not dotted out or starred out like is usually is with password protection forms. I think that this can be changed but that is beyond the scope of this tutorial.
This code is pretty basic. To use this you will need to change the line that says “whatever password you choose here” to whatever you want the password to be. And then change the “name of the form that you want to password protect” to the name of your form. Now, you can change “Enter Password” to whatever message you want to appear when the password box comes up, and likewise, you can change the “Wrong Password?” part to whatever message that you want to display when the user enters the wrong password or does not enter any password at all.
So there you have it, a pretty easy and basic password protection system to password protect a form or report in Microsoft access. This will work with just about any version of Access, so give it a try. Just remember that this is not really completely secure becuase anyone who knows how can just look at the form in design view and then check the ‘onload’ event code to discover the hard-coded password, but the average user will never know how to do this anyway, so this is a reasonably decent solution.
Thanks for reading this tutorial on password protecting a form or report in a microsoft access database.

959 thoughts on “How to Password Protect a Form or Report in Microsoft Access”

  1. Great goods from you, man. I’ve be mindful your stuff prior to and you are just too great. I actually like what you’ve bought right here, really like what you’re stating and the way by which you assert it. You are making it enjoyable and you continue to take care of to keep it wise. I can not wait to read much more from you. That is actually a terrific web site.

  2. Hiya, I am really glad I’ve found this info. Nowadays bloggers publish only about gossips and internet and this is really irritating. A good web site with exciting content, that’s what I need. Thanks for keeping this web-site, I’ll be visiting it. Do you do newsletters? Can’t find it.

  3. Everyone loves what you guys are up too. This sort of clever work and coverage! Keep up the very good works guys I’ve you guys to our blogroll.

  4. It is the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I wish to suggest you some interesting things or suggestions. Maybe you can write next articles referring to this article. I desire to read even more things about it!

  5. I think this is one of the most important info for me. And i’m glad reading your article. But wanna remark on few general things, The site style is perfect, the articles is really nice : D. Good job, cheers

  6. Do you have a spam issue on this blog; I also am a blogger, and I was wanting to know your situation; we have created some nice procedures and we are looking to trade solutions with others, please shoot me an e-mail if interested.

  7. Excellent goods from you, man. I’ve understand your stuff previous to and you’re just extremely excellent. I really like what you have acquired here, certainly like what you’re saying and the way in which you say it. You make it enjoyable and you still take care of to keep it smart. I cant wait to read much more from you. This is really a great web site.

  8. I’m really loving the theme/design of your blog. Do you ever run into any web browser compatibility problems? A handful of my blog readers have complained about my website not working correctly in Explorer but looks great in Chrome. Do you have any suggestions to help fix this issue?

  9. Heya superb blog! Does running a blog similar to this take a large amount of work? I’ve no understanding of coding however I had been hoping to start my own blog soon. Anyways, should you have any recommendations or tips for new blog owners please share. I know this is off subject nevertheless I simply needed to ask. Kudos!

  10. It’s really a nice and useful piece of info. I am glad that you just shared this useful information with us. Please keep us up to date like this. Thank you for sharing.

  11. There are some attention-grabbing closing dates in this article however I don’t know if I see all of them center to heart. There is some validity however I’ll take hold opinion till I look into it further. Good article , thanks and we wish more! Added to FeedBurner as well

  12. Hi there, just became aware of your blog through Google, and found that it’s truly informative. I¡¦m going to watch out for brussels. I will appreciate if you continue this in future. Numerous people will be benefited from your writing. Cheers!

  13. We are a gaggle of volunteers and starting a brand new scheme in our community. Your website provided us with valuable info to work on. You have done an impressive process and our whole group will probably be grateful to you.

  14. Awfully enlightening many many thanks, It looks like your current readers could possibly possibly want even more blog posts similar to this continue the good effort.

  15. It’s appropriate time to make some plans for the future and it is time to be happy. I’ve read
    this post and if I could I want to suggest you few interesting things or suggestions.

    Maybe you could write next articles referring to this article.
    I desire to read even more things about it!

    Also visit my site :: Maroc Referencement

  16. As I website possessor I believe the content material here is rattling fantastic , thankyou for your efforts.

Comments are closed.