Select Case

  • Thread starter Thread starter jean.ulrich
  • Start date Start date
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
 
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
 
"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
 

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

Back
Top