Password Protect a form (1 Viewer)

G

Garyj

Guest
How do you make a form password protected?
 

SAK

Registered User.
Local time
Yesterday, 20:25
Joined
Jun 5, 2003
Messages
43
One way, would be under the forms properties, at the event tab extablish a routine for the On Open event that would have an input box whose data must match a predefined variable (your password).

If the password matches, the routine opens the form. If not, a message box could be instituted to advise the password is incorrect and to try again.

Just worked with that topic recently.
 

llkhoutx

Registered User.
Local time
Yesterday, 19:25
Joined
Feb 26, 2001
Messages
4,018
I've used the user system login name to create a table of users entitled to open a certain form.

This way users don't have to do anything special, they're either in the table and permitted access or not.
 

sdawson

Registered User.
Local time
Today, 01:25
Joined
Apr 22, 2003
Messages
165
This code I have used a few times and works OK.
It's in the On Click event procedure on the button that opens the form.
I got it off here a few months ago.
Hope it helps.

++++++++++++++++++++++++++++++++++++++++++++

Private Sub Command17_Click()
On Error GoTo Err_Command17_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim strMsg As String
Dim strinput As String


stDocName = "status closed"
Beep
Beep
strMsg = "This form is used only by authorised personnel" & vbCrLf & vbLf & "Please key the password to allow access."
strinput = InputBox(Prompt:=strMsg, title:="Password")
If strinput = "santa" Then 'password is correct

DoCmd.OpenForm stDocName, , , stLinkCriteria

Else 'password is incorrect
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access ''Close CCAR''.", vbCritical, "Invalid Password"
Exit Sub
End If


Exit_Command17_Click:
Exit Sub

Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub
 
G

Garyj

Guest
The code works great. Is their a way to have the password not show when keying it in?
 

sdawson

Registered User.
Local time
Today, 01:25
Joined
Apr 22, 2003
Messages
165
Sorry, not got fix.
Tried to find this on forum but got dead end.
This has not been an issue for my users but would like fix.
If u solve this or anyone else has fix, left me know please.
 

neileg

AWF VIP
Local time
Today, 01:25
Joined
Dec 4, 2002
Messages
5,975
Is their a way to have the password not show when keying it in?
Format the text box so that the background and the font are the same colour.

Or, bind the textbox to a table and define an input mask as password.
 
Last edited:

Not A PHB

Registered User.
Local time
Yesterday, 20:25
Joined
Oct 1, 2002
Messages
17
Garyj said:
The code works great. Is their a way to have the password not show when keying it in?

Sure just select Properies/Data/Input Mask and Password is one of the predefined Masks. Works like a charm and you don't need to bind it to a table.

HTH,

Lance
 
G

Garyj

Guest
Everyone sugguestiong is great but it would change my direction. I would like to keep the code that I am using from this form but just not allow the password to actually be shown if possible.

Is thier a way to modify the code to get the password from showing?

Thanks
 

neileg

AWF VIP
Local time
Today, 01:25
Joined
Dec 4, 2002
Messages
5,975
??

As Lance says, you can change the input mask of the text box on your form. This involves no changes to the code.
 

Not A PHB

Registered User.
Local time
Yesterday, 20:25
Joined
Oct 1, 2002
Messages
17
Garyj said:
Everyone sugguestiong is great but it would change my direction. I would like to keep the code that I am using from this form but just not allow the password to actually be shown if possible.

Is thier a way to modify the code to get the password from showing?

Thanks

I don't think there is a way to use an input mask on an input box but what you can do is create your own form and use it in place of the input box with very little change to your code and the addition of the new form. I've attached the sample database using your existing code, command button name and form names so you should just need to copy this code into your command 17 button:
Private Sub Command17_Click()
On Error GoTo Err_Command17_Click

Beep
Beep
DoCmd.OpenForm "Password"


Exit_Command17_Click:
Exit Sub

Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub

and then import the password form from my sample database. The rest of the code that was in your command17_Click event has been adapted to the cmdOK_Click event in the password form. Here is that code:
Private Sub cmdOK_Click()
Dim stDocName As String
Dim stLinkCriteria As String
Dim strinput As String


stDocName = "status closed"
strinput = Me.txtPassword
If strinput = "santa" Then 'password is correct
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else 'password is incorrect
DoCmd.Close
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access ''Close CCAR''.", vbCritical, "Invalid Password"

Exit Sub
End If

End Sub

Here is the code for the cmdCancel_Click event in the form.

Private Sub cmdCancel_Click()
DoCmd.Close
End Sub

Additional info:

I've set the input mask property of txtPassword to "Password" and made the password form modal = Yes, border= dialog and pop up = yes so that the form behaves the same as an input box. To the end user it works exactly the same.

I hope this helps,

Lance
 

MossleyMike

Registered User.
Local time
Today, 01:25
Joined
Mar 31, 2003
Messages
11
Password Protect a Form

Looking at this thread, I've used the same kind of code, input mask etc.

What would interest me is a way of hiding/encrypting the actual password within the event code, i.e. rather than:

If str = "Password" then open database etc

to have

If str = "&^%@@" then open database etc

where "&^%@@" is actually "Password"

It's all very well using a Password input mask, but if someone can get to the event code the password is hardcoded in for all to see !!
 

ghudson

Registered User.
Local time
Yesterday, 20:25
Joined
Jun 8, 2002
Messages
6,195
If somebody can actually see your VBA then your db is not correctly secured to prevent that type of access.
 

MossleyMike

Registered User.
Local time
Today, 01:25
Joined
Mar 31, 2003
Messages
11
I don't have a problem with the security on the particular database in question - although I never underestimate the "power of the user" !

The original question, therefore still remains unanswered ...
 

sdawson

Registered User.
Local time
Today, 01:25
Joined
Apr 22, 2003
Messages
165
password protected form

Boys oh boys oh boys!
The lad said the the input box method was OK.
Could someone post the code to change the password fonts to the background colour.
We can all rest happy then.

Ta
 

ghudson

Registered User.
Local time
Yesterday, 20:25
Joined
Jun 8, 2002
Messages
6,195
You can not modify any formats [font, color, input masks] in an input box.
 

Users who are viewing this thread

Top Bottom