ACC2000: How to Create a Password Protected Form or Report

TxSteve

Registered User.
Local time
Today, 15:57
Joined
Dec 28, 2006
Messages
35
Article ID : 209871
Last Review : June 23, 2005
Revision : 3.0


I'm a rookie, and found this code on the MS site. I followed the steps and it works great. I am only protecting one form and it does what I need. Very simple.

My question is, how in the wild world of sports do you change the default password of "PASSWORD"
 
Look at step 20. It tells you how to come up with a different keycode for a password. Assuming you recreated what they told you to (and it sounds like you did), then open the Immediate Window in the VBA Editor (Ctrl-G is the shortcut) and type:

?KeyCode("your_password_here")

That will return a number for you. Then, in the table named tblPasswords, in the ObjectName field, put the name of the form you want to protect, and then the key code you just generated in the Immediate Window using the KeyCode function.

Finally, pick up at step 10 and go through 17, replacing the "Orders" form in the example with the name of the form you want to protect.

Use step 21 to hide the tblPassword table if you like. It's already fairly secure without that step, although if you know the code that generated the password (provided in the example), a competent programmer can easily reverse-engineer it. Many users, though, seem very content with bolding a word or changing font size. You know your user base better than me. :)
 
Ugh! I did everything except for inserting my password in here -> ?KeyCode("your_password_here") No matter what I did, I kept returning the same value ...Duh!

Thank you very much for quickly helping. Now I can finish this and get some much needed sleep.

**Update - 5 minutes has gone by, new password and all is working! Have a great night.

God Bless,
-Steve
 
Last edited:
Glad it worked. It's almost always something goofy that gets missed, especially if you've been staring at the same thing for hours. :)

Note that you can call the KeyCode function from anywhere, not just the Immediate Window. Therefore, you could make a "generate a new keycode" form only for you (or whomever the administrator is) to use, and you could password protect it as well. From there, have a textbox name txtPassword, and after they leave the textbox (the BeforeUpdate event), put in:

MsgBox "Keycode for " & txtPassword & " is " & KeyCode(txtPassword)

From there, you can manually add that keycode to tblPassword along with the associated forms. You can even automate the whole thing and have the keycode and the forms to protect automatically appended to tblPassword, etc.

You got the basics down though, so the rest is up for your experimentation. :)
 
hmm moniker, i didn;t notice the step 20 where is it??
 
Article ID : 209871
Last Review : June 23, 2005
Revision : 3.0

That Article is the KB (Knowledge Base) number from MSDN. Go to where he said he went MS online, (specifically msdn.microsoft.com) and search for "Knowledge Base". Once you're there, search on that article number.

I think I'm just belligerent at this point, but these are obvious Q&A answers. Knowing how to use Google, much less MSDN, is just part of programming, especially when you're stuck. There are a handful of people here that attempt to answer the questions asked, but self-help is a lot more convenient than hand-holding throughout the process.

If you are this new to Access, look at the NorthWind DB included with Access that includes all sorts of structures (including subforms, pictures, etc.).

I'm not trying to sound like the best answer provider ever as I've learned from others here as well as you surely have, but at the same time, the same questions being asked over and over can become redundant. I know that many people are learning and asking questions as they go, but you learn on your own, not by asking questions everytime a minor hiccup happens. You learn from trial and error, not from provided solutions. You learn from determination, not relaxation.
 
Moniker said:
I think I'm just belligerent at this point, but these are obvious Q&A answers. Knowing how to use Google, much less MSDN, is just part of programming, especially when you're stuck.
Let's also not forget that one of the most helpful things you can do to get an explanation is to just hit the F1 key and use the help files that ship with Access (or any other application) as hundreds of basic questions are answered there, yet we constantly see people asking them here.
 
Since my original post and fantastic assistance I received, this feature has been working great for me. However, this morning, I split my database. I placed the backend on our network and kept the frontend on my desktop. Then I took the frontend and changed it to the MDE format. (So far so good)

I selected my protected form and my Enter Password box popped up correctly. I entered my password and clicked on the Enter button. Then I received the following message,
"Error 3219" Invalid Operation. (Note: I can select ok and it accepts password)

I've been GoogleSofting and think it might have something to do with this,

PRB: Jet Doesn't Support QueryDefs on a Non-Attached ODBC Table
Article ID : 149055
Last Review : March 14, 2005
Revision : 2.2

The code for my Login module is;
Public MyPassword
Public Function KeyCode(Password As String) As Long
' This function will produce a unique key for the
' string that is passed in as the Password.
Dim I As Integer
Dim Hold As Long

For I = 1 To Len(Password)
Select Case (Asc(Left(Password, 1)) * I) Mod 4
Case Is = 0
Hold = Hold + (Asc(Mid(Password, I, 1)) * I)
Case Is = 1
Hold = Hold - (Asc(Mid(Password, I, 1)) * I)
Case Is = 2
Hold = Hold + (Asc(Mid(Password, I, 1)) * _
(I - Asc(Mid(Password, I, 1))))
Case Is = 3
Hold = Hold - (Asc(Mid(Password, I, 1)) * _
(I + Len(Password)))
End Select
Next I
KeyCode = Hold
End Function

Code for my Password Form is,
Private Sub CheckPassword_Click()
If IsNull(Forms!frmPassword!Text0.Value) Then
MsgBox "You cannot enter a blank Password. Try again."
Me!Text0.SetFocus
Else
MyPassword = Me!Text0.Value
DoCmd.Close acForm, "frmPassword"
End If
End Sub

Any suggestions?
 

Users who are viewing this thread

Back
Top Bottom