Code

K

Khartoum

I have a password form, the code behind the OK button is as follows:
Private Sub okbutton_Click()
If Forms![password form].text_password = "fav1m" Then DoCmd.OpenForm "name1"
Else: If Forms![password form].text_password = "ro488" Then DoCmd.OpenForm
"name2" _
Else: If Forms![password form].text_password = "cb831" Then DoCmd.OpenForm
"name3" _
Else: If Forms![password form].text_password = "pc955" Then DoCmd.OpenForm
"name4"
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub
So depending on the password, a particular form will open (each form has to
be secure) but as there are over 20 forms i keep getting a message about too
many continuation lines. Can anybody help me with the code to prevent this
Thanks John Mc
 
J

Jerry Whittle

Put the passwords like fav1m in one column of a table. Put in the matching
form name in the other column of the same table. Then do something like
DLookup of that table to match the password to a form.

Having said that, if you think your database is secure with such a system,
you are wrong. If you need the database to be secure, use the built-in User
Level Security feature.
 
K

Khartoum

ok thanks,
ps i would use the built-in User
Level Security feature if it wasn't an enigma to me. Unfortunately, users
are administered remotely which does not help


Jerry Whittle said:
Put the passwords like fav1m in one column of a table. Put in the matching
form name in the other column of the same table. Then do something like
DLookup of that table to match the password to a form.

Having said that, if you think your database is secure with such a system,
you are wrong. If you need the database to be secure, use the built-in User
Level Security feature.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Khartoum said:
I have a password form, the code behind the OK button is as follows:
Private Sub okbutton_Click()
If Forms![password form].text_password = "fav1m" Then DoCmd.OpenForm "name1"
Else: If Forms![password form].text_password = "ro488" Then DoCmd.OpenForm
"name2" _
Else: If Forms![password form].text_password = "cb831" Then DoCmd.OpenForm
"name3" _
Else: If Forms![password form].text_password = "pc955" Then DoCmd.OpenForm
"name4"
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub
So depending on the password, a particular form will open (each form has to
be secure) but as there are over 20 forms i keep getting a message about too
many continuation lines. Can anybody help me with the code to prevent this
Thanks John Mc
 
K

Khartoum

i don't suppose you can give me an example of how to use that code in my
example could you?

Jerry Whittle said:
Put the passwords like fav1m in one column of a table. Put in the matching
form name in the other column of the same table. Then do something like
DLookup of that table to match the password to a form.

Having said that, if you think your database is secure with such a system,
you are wrong. If you need the database to be secure, use the built-in User
Level Security feature.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


Khartoum said:
I have a password form, the code behind the OK button is as follows:
Private Sub okbutton_Click()
If Forms![password form].text_password = "fav1m" Then DoCmd.OpenForm "name1"
Else: If Forms![password form].text_password = "ro488" Then DoCmd.OpenForm
"name2" _
Else: If Forms![password form].text_password = "cb831" Then DoCmd.OpenForm
"name3" _
Else: If Forms![password form].text_password = "pc955" Then DoCmd.OpenForm
"name4"
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub
So depending on the password, a particular form will open (each form has to
be secure) but as there are over 20 forms i keep getting a message about too
many continuation lines. Can anybody help me with the code to prevent this
Thanks John Mc
 
J

John Spencer

SELECT CASE Forms!PasswordForm!Text_Password
Case "Favim"
...
Case "ro488"
...
Case else
...
END SELECT

As noted elsewhere, you might be better off with a table that has the password
and form name

THen you could use

Dim strFormName as string

'Assumption: Table named "OpenThisForm"
'with two fields Formname and tPassword.
strFormName = Nz(DLookup("FormName","OpenThisForm","tPassword= """ &
Forms!PasswordForm!Text_Password & """"),"")

If Len (strFormName)> 0 then
DoCmd.OpenForm strFormName
else
MsgBox "You have entered an incorrect password", vbOKCancel
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
K

Khartoum

Thanks John, will give it a go

John Spencer said:
SELECT CASE Forms!PasswordForm!Text_Password
Case "Favim"
...
Case "ro488"
...
Case else
...
END SELECT

As noted elsewhere, you might be better off with a table that has the password
and form name

THen you could use

Dim strFormName as string

'Assumption: Table named "OpenThisForm"
'with two fields Formname and tPassword.
strFormName = Nz(DLookup("FormName","OpenThisForm","tPassword= """ &
Forms!PasswordForm!Text_Password & """"),"")

If Len (strFormName)> 0 then
DoCmd.OpenForm strFormName
else
MsgBox "You have entered an incorrect password", vbOKCancel
END IF

John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
I have a password form, the code behind the OK button is as follows:
Private Sub okbutton_Click()
If Forms![password form].text_password = "fav1m" Then DoCmd.OpenForm "name1"
Else: If Forms![password form].text_password = "ro488" Then DoCmd.OpenForm
"name2" _
Else: If Forms![password form].text_password = "cb831" Then DoCmd.OpenForm
"name3" _
Else: If Forms![password form].text_password = "pc955" Then DoCmd.OpenForm
"name4"
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub
So depending on the password, a particular form will open (each form has to
be secure) but as there are over 20 forms i keep getting a message about too
many continuation lines. Can anybody help me with the code to prevent this
Thanks John Mc
 

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

Similar Threads

Message - Too many continuation lines 1
runtime error 3
Open Form Code 1
DLookup failing 5
recordset issue 5
Users log 4
Run-Time Error 2501 The OpenForm action was cancelled 1
Access Passing data from a form to another form! 0

Top