Select Case

J

jean.ulrich

Hi

I have a text box on a form so user can write a password

I also have a button

here what I want

If the user put "123" and click the button, form "Employees" open
if the user put "abc" and click the button, form "Customers" open
if the user put "xxx" anc click the button, form "Products" open

I know I should use the select case method, but I don't know how to do
it, how to create the code, how to start

Should I create a statement and then on the "click" event of the
button put someting like "call the statement" or put the code on the
click event of the button !!!!!

thanks for your help
 
W

Wayne-I-M

Private Sub TextBoxName_Click()
Static Counter As Integer
If txtPassword = "123" Then
DoCmd.OpenForm "Employees", acNormal, "", "", , acNormal
Else
If txtPassword = "ABC" Then
DoCmd.OpenForm "Customers", acNormal, "", "", , acNormal
Else
If txtPassword = "XXX" Then
DoCmd.OpenForm "Products", acNormal, "", "", , acNormal
Else
If Counter < 2 Then
MsgBox "The password you entered is not correct - try again - MAX 3
ATTEMPTS?", vbOKOnly, "Database entry declined"
Counter = Counter + 1
txtPassword = ""
Else
DoCmd.Quit
End If
End If
End If
End Sub




Change textBoxName to what it really is

You can delete this bit if you want (but I would leave it on)
If Counter < 2 Then
MsgBox "The password you entered is not correct - try again - MAX 3
ATTEMPTS?", vbOKOnly, "Database entry declined"
Counter = Counter + 1
txtPassword = ""

Hope this helps
 
P

Pieter Wijnen

"Prettier" is

Select Case Me.txtPassword.Value
Case "123"
DoCmd.OpenForm "Employees", acNormal
Case "ABC"
DoCmd.OpenForm "Customers"", acNormal
Case Else
MsgBox "Invalid Password"
End Select

HTH

Pieter
 
Top