Password Protect Form

D

DHSBob

I am trying to password protect a form. I am terrible in coding and tried to
use the code from other posts but it didn't work. Here is the code for the
button to access the form. Would someone be kind enough to help me with this?

Private Sub Command13_Click()
On Error GoTo Err_Command13_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_Office Update"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command13_Click:
Exit Sub

Err_Command13_Click:
MsgBox Err.Description
Resume Exit_Command13_Click

End Sub
 
G

Golfinray

Put this in the onclick event on the command button. Try

Dim strPassword As String
strPassword - Inputbox("enter your password")
If strPassword = "whatever you want their password to be" then
DoCmd.openform "yourformyouwantto open",,,, acForm
else
end if
 
A

Arvin Meyer [MVP]

I use the api code to identify the Windows authenticated username:

http://www.mvps.org/access/api/api0008.htm

and simply add the If statement to the form's code:

If fOSUserName() = "Arvin" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "You are not allowed to use this form", vbOKOnly
DoCmd.CancelEvent
End If

With the construct above, only I can get in. If there's more than I, use an
OR statement or a Select Case statement, or save the names in a table and
look the name up. This way you can assure which user is allowed without
having to deal with a password.
 
A

Arvin Meyer [MVP]

Try this one:

Private Sub Form_Open(Cancel As Integer)
If InputBox("Type the secret word") = "Groucho" Then
Else
Cancel = True
End If
End Sub
 
P

poohtender

Daniel, First I want to say I am very new at this and have no training so I
am learning this all by trial and error so please forgive me if I sound
stupid. I used the information from your link to create a protected form for
my database and it worked fine. However how would I change the password in
this method to one of my choosing.
 
L

lmossolle

Under what category do you put this under?

Arvin Meyer said:
I use the api code to identify the Windows authenticated username:

http://www.mvps.org/access/api/api0008.htm

and simply add the If statement to the form's code:

If fOSUserName() = "Arvin" Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "You are not allowed to use this form", vbOKOnly
DoCmd.CancelEvent
End If

With the construct above, only I can get in. If there's more than I, use an
OR statement or a Select Case statement, or save the names in a table and
look the name up. This way you can assure which user is allowed without
having to deal with a password.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top