Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    64

    Question Unanswered: How to open form by pressing enter

    I have a form where users put their name/password to open another form. After putting the password the users click a button I created to open the other form.
    My question is this: I want the users to be able to open the other form by pressing Enter as well as clicking on the button.
    How can I do this?

    Here's the code behind the button I created. How can I add to this code so users can press enter to open the form if they like?
    ------------------------------------------------------
    Private Sub Command4_Click()
    On Error GoTo Err_Command4_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim conDB As ADODB.Connection
    Dim rsSalesReps As ADODB.Recordset
    Dim strSalesRepPwd As String

    Set conDB = New ADODB.Connection
    conDB.Provider = "Microsoft.Jet.OLEDB.4.0"
    conDB.Open "\\backup\departments\mrkt\Contact_Management_Data base\Contact_Management_Database.mdb", "Admin", ""

    Set rsSalesReps = New ADODB.Recordset
    rsSalesReps.Open "select SalesRepPwd from SalesReps where SalesRepID=" & Me![Combo0], conDB
    strSalesRepPwd = Trim(rsSalesReps!SalesRepPwd & "")

    rsSalesReps.Close
    Set rsSalesReps = Nothing
    conDB.Close
    Set conDB = Nothing

    Text2.SetFocus
    If strSalesRepPwd = Trim(Text2.Text & "") Then

    stDocName = "Contacts"

    If Me![Combo0] <> 1 Then '1 = Admin
    stLinkCriteria = "[SalesRep]=" & Me![Combo0]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Else
    DoCmd.OpenForm stDocName
    End If

    Form_Contacts.gstrSalesRep = Me![Combo0]

    Else
    MsgBox "Wrong Password"
    End If

    Exit_Command4_Click:
    Exit Sub

    Err_Command4_Click:
    MsgBox Err.Description
    Resume Exit_Command4_Click

    End Sub
    ------------------------------------------------------

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    in the Properties of that text Feild build a Event Base on the Key Press

    Private Sub Address_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    'has press enter
    call Command4_Click

    Else

    End If

    End Sub
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    Could you have your code run on Lost Focus on the where password is entered?

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    myle's method will most likely work best....

    Supposing the name for your password textbox is myPasswordTextBoxName. Your KeyDown event for the TextBox should look like.....

    Code:
    Private Sub myPasswordTextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then 'vbKeyReturn is a global Constant for the Enter key.
       KeyCode = 0  
       Call Command4_Click
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •