By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

VBA procedure after else

P: 4
Could someone help me, please. I have a login form in Ms Access with two fields "User name" and "Password" and Command button. If I write incorrect password or user name and click on the command button it also access. Command Button has a procedure (on click):
Private Sub Command4_Click()
If IsNull(Me.User_name) Or Me.User_name = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Exit Sub
End If

If IsNull(Me.User_password) Or Me.User_password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Exit Sub
End If

If Me.User_password.Value = (DLookup("[Password]", "Passwords", "[Username_ID]=" _
& Me.User_name.Value)) Then

DoCmd.Close acForm, "Login_form", acSaveNo
DoCmd.OpenForm "New_form"


please could someone write what comes next after Else. I think there should be MsgBox that password is incorrect.
Nov 15 '06 #1
Share this Question
Share on Google+
6 Replies

Expert 100+
P: 1,418
Msgbox "Incorrect pwd"

End if
Nov 15 '06 #2

P: 4
Now when I click on Command Button there's run time error 2001 'You canceled previous operation'. Suggestions, why it is so???
Nov 15 '06 #3

Expert Mod 15k+
P: 31,494
This is what you need I'm sure.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2.     If Nz(User_name, "") = "" Then
  3.         MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  4.         User_name.SetFocus
  5.         Exit Sub
  6.     ElseIf Nz(User_password, "") = "" Then
  7.         MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  8.         User_password.SetFocus
  9.         Exit Sub
  10.     ElseIf User_password <> DLookup("[Password]", _
  11.                                   "Passwords", _
  12.                                   "[Username_ID]='" & User_name & "'") Then
  13.         MsgBox "The Password you have entered is invalid.", vbOKOnly, _
  14.                "Required Data"
  15.         User_password.SetFocus
  16.         Exit Sub
  17.     Else
  18.         DoCmd.Close acForm, "Login_form", acSaveNo
  19.         DoCmd.OpenForm "New_form"
  20.     End If
  21. End Sub
Nov 15 '06 #4

Expert 100+
P: 1,418
In fact an algoritme like this is helpfull but not enough protected!

It is better to have a possibility to quit the application if user tries more than 3 times to enter!

If not early or late /tôt ou tard/ who wants enter will enter...

The computer can run a macro that will seek for the password fo an hour and finnally crac the password

I prefer to quit Access on wrong password! In my systems is like this

Take care about!
Nov 15 '06 #5

Expert Mod 15k+
P: 31,494
That is very good advice.
It would also be worth considering applying some sort of encryption to the passwords stored in the table.
You're welcome to use this routine that I use.
It's not ultra-secure, but it does work both ways (so Scramble(Scramble("Text")) = "Text")
Expand|Select|Wrap|Line Numbers
  1. 'If I told you what this did I'd have to kill you.
  2. Public Function Scramble(strPW As String)
  3.     Dim intIdx As Integer
  5.     Scramble = strPW
  6.     For intIdx = 1 To Len(strPW)
  7.         Mid(Scramble, intIdx, 1) = _
  8.             Chr(&H40 Or (Not Asc(Mid(strPW, intIdx, 1))) And &H3F)
  9.     Next intIdx
  10. End Function
Nov 15 '06 #6

P: 4
Thanks for help
Nov 16 '06 #7

Post your reply

Sign in to post your reply or Sign up for a free account.