Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter key to Execute

Status
Not open for further replies.

chanman525

IS-IT--Management
Oct 7, 2003
169
US
Ok, i have just spent the last couple hours scouring the forum trying to find a resolution to my delima. I am certain that after I post this that someone will probably refer me to a previous post. If so please forgive me as I have searched on many diff sequences to find what I needed.

Now that I have my disclaimer out of the way....

I have a form that is used for password control. But the problem I have is that I can not get it to execute the event when I press the ENTER key. I have the behaviour set to new line (as stated in other posts) and I have tried the Key Press and Key Down subs.

Here is my code;
Code:
Private Sub TxtPasswordInput_KeyPress(KeyAscii As Integer)
Dim stDocName As String
Dim stLinkCriteria As String

If (KeyAscii = 13) Then

        Select Case Me.TxtPasswordInput

    Case "not4u2no"
        Forms!frmmain!BtnAssignTask.Enabled = True
        Forms!frmmain!BtnOpenConfig.Enabled = True
        Forms!frmmain!BtnOpenFrmProjectManager.Enabled = True
        Me.TxtPasswordInput.Value = ""
        DoCmd.Close acForm, "frmPassword"
        
    Case "project"
            DoCmd.Close acForm, "FrmPassWord"
            On Error GoTo Err_BtnOpenFrmProjectManager_Click
            stDocName = "FrmProjectManager"
            stLinkCriteria = "[ID]=" & Forms!frmmain![ID]
            DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
            
Exit_BtnOpenFrmProjectManager_Click:
        Exit Sub
        
Err_BtnOpenFrmProjectManager_Click:
            MsgBox Err.Description & Chr(13) & "Are you on a valid record?"
            Resume Exit_BtnOpenFrmProjectManager_Click
            
    Case Else
        MsgBox "You entered an invalid password!", vbExclamation, "Invalid Password"
        Me.TxtPasswordInput.Value = ""
        Me.TxtPasswordInput.SetFocus
    End Select

    End If
End Sub

Right now when I press the ENTER key I get invalid password and I am certain that this is due to the carriage return being sent by the ENTER Key.

Any ideas would be greatly appreciated.
 
randy,
What button are you referring to? I am confused? The field is a text field? are you talking about the default value of the field?

I did realize that the code I pasted as an error trap that references a button. That is because I pasted the code into the KeyPress of the text field to test it out. When it is on the button all works well, but I want the user to have the option of hitting the ENTER key upon completion of entering the password instead of always having to click the button.
 
Put your code in the OnClick event of a command button. Set the button's default property to YES. When you type in your password and press the Enter key, the OnClick event will fire and the code will run.


Randy
 
Once again I get nailed on something so simple!! Thank you for the time randy!!! Works like a charm. Makes me wonder why there are some many long pieces of code to handle something so simple.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top