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

Need help with password form

P: 72
Hey Everybody,
I have a form with a label ("Enter Password"), a textbox (with a password InputMask), and two command buttons ("OK" and "Cancel"). I've successfully written code for the "OK" command button to check the password in the textbox with an OnClick event. It then either opens the authorized form or it doesn't.

However, I would also like to set an event for the textbox, so when the user hits the Enter key, the same code is executed as for the "OK" button's OnClick event. I tried running the code below, but I kept getting a response stating, "This action can't be carried out while processing a form or report event."

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEnterPassword_Exit(Cancel As Integer)
  2. On Error GoTo Err_txtEnterPassword_Exit
  3.  
  4.     Dim stDocName As String, stLinkCriteria As String
  5.  
  6.     If Me.txtEnterPassword = "proc_eng" Then
  7.         ' Password is correct; open form below and exit Main Menu.
  8.         stDocName = "Add Column"
  9.         DoCmd.OpenForm stDocName, , , stLinkCriteria
  10.         DoCmd.Close acForm, "Main Menu"
  11.         DoCmd.Close acForm, "Authorization Required"
  12.     Else
  13.         MsgBox "Incorrect Password", vbOKOnly, "Access Denied"
  14.         ' Password is incorrect.
  15.     End If
  16.  
  17. Exit_txtEnterPassword_Exit:
  18.     Exit Sub
  19.  
  20. Err_txtEnterPassword_Exit:
  21.     MsgBox Err.Description
  22.     Resume Exit_txtEnterPassword_Exit
  23. End Sub
I found that the DoCmd.Close acForm, "Authorization Required" line of code was the problem. If I delete it, the rest of the code works. However, I need that form to close. What did I do wrong? How do I fix it? Please post the exact changes that need to be made.

Thanks!
Jun 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: 72
Hey Everybody,
I have a form with a label ("Enter Password"), a textbox (with a password InputMask), and two command buttons ("OK" and "Cancel"). I've successfully written code for the "OK" command button to check the password in the textbox with an OnClick event. It then either opens the authorized form or it doesn't.

However, I would also like to set an event for the textbox, so when the user hits the Enter key, the same code is executed as for the "OK" button's OnClick event. I tried running the code below, but I kept getting a response stating, "This action can't be carried out while processing a form or report event."

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEnterPassword_Exit(Cancel As Integer)
  2. On Error GoTo Err_txtEnterPassword_Exit
  3.  
  4.     Dim stDocName As String, stLinkCriteria As String
  5.  
  6.     If Me.txtEnterPassword = "proc_eng" Then
  7.         ' Password is correct; open form below and exit Main Menu.
  8.         stDocName = "Add Column"
  9.         DoCmd.OpenForm stDocName, , , stLinkCriteria
  10.         DoCmd.Close acForm, "Main Menu"
  11.         DoCmd.Close acForm, "Authorization Required"
  12.     Else
  13.         MsgBox "Incorrect Password", vbOKOnly, "Access Denied"
  14.         ' Password is incorrect.
  15.     End If
  16.  
  17. Exit_txtEnterPassword_Exit:
  18.     Exit Sub
  19.  
  20. Err_txtEnterPassword_Exit:
  21.     MsgBox Err.Description
  22.     Resume Exit_txtEnterPassword_Exit
  23. End Sub
I found that the DoCmd.Close acForm, "Authorization Required" line of code was the problem. If I delete it, the rest of the code works. However, I need that form to close. What did I do wrong? How do I fix it? Please post the exact changes that need to be made.

Thanks!

Can someone help me?
Jun 7 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
Try putting your code in the After Update event of the textbox
Jun 13 '07 #3

hyperpau
Expert 100+
P: 184
Can someone help me?
Put an after_update event on the txtbox
that would set focus on the OK key.

So as soon as user inputs text, focus goes to OK key and
the moment they press enter, the ok key function is called
Jun 13 '07 #4

100+
P: 222
I had the same problem once and I changed the order and it works

try to do that ...
DoCmd.Close acForm, "Authorization Required"
DoCmd.Close acForm, "Main Menu"
DoCmd.OpenForm stDocName, , , stLinkCriteria


I'm not an expert member but I think it will works ..please try it and tell me if it works

thank you
Jun 25 '07 #5

Post your reply

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