Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2004
    Posts
    277

    Unanswered: the enter key in a text box

    how do you activate the code after pressing enter in a text box?

  2. #2
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Create a button -> Go into the properties -> Set as default button -> Put the code behind the button

    When you press enter, so long as it isnt in a memo field when enter is the next line command, it will execute the code behind the button

  3. #3
    Join Date
    Dec 2004
    Posts
    277
    huh? not understanding that at all

  4. #4
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Right, if you want to run code on your page just by pressing the enter key then you create a button on the page, go into the properties of that button and make the setting "Default" = yes

    Put whatever code you want on the button

    When you press enter in any TEXT BOX on the page then the code behind the button will run, you can only run one piece of code like this per form.

    I dont think you can capture then enter key when it is pressed inside a text box.

    It is effectivly just like pressing the button but all you do is press enter in a text box.

    Hope that was a little clearer

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you can capture the enter key in one textbox.
    try this:

    Private Sub myText_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
    MsgBox "User hit the Enter key"
    End If
    End Sub

    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Dec 2004
    Posts
    277
    thanks that was what i was looking for

  7. #7
    Join Date
    Dec 2004
    Posts
    277
    I am trying to get it to look for to make sure the password is correct otherwise prompt, make the textbox null and give it the control.

    My code looks like this

    Private Sub Text8_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim pass As String
    pass = "bigbud"
    If KeyCode = 13 And Me.Text8 = pass Then
    DoCmd.Close acForm, "Login"
    DoCmd.OpenForm "Main"
    ElseIf KeyCode = 13 And Me.Text8 <> pass Then
    Me.Text8 = Null
    DoCmd.GoToControl Text8
    MsgBox "Incorrect Password. Please Try Again.", , "Incorrect Password"
    End If
    End Sub

    But that does not work

  8. #8
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    Why does it not work? What error is it giving?
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  9. #9
    Join Date
    Jul 2004
    Location
    Blackburn, UK
    Posts
    169
    I'd use

    Text8.setfocus aswell instead of gotocontrol
    Based on DAO 3.6 and Access 2000 + 2003
    VB.Net 2005 + ADO.Net

  10. #10
    Join Date
    Dec 2004
    Posts
    277
    I added the code to the form on KeyDown

    that seemed to work just fine

    FINAL ANSWER:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim pass As String
    pass = "bigbud"
    Text8.SetFocus
    If KeyCode = 13 And Me.Text8 = pass Then
    DoCmd.Close acForm, "Login"
    DoCmd.OpenForm "Main"
    ElseIf KeyCode = 13 And Me.Text8 <> pass Then
    Me.Text8 = Null
    Text8.SetFocus
    MsgBox "Incorrect Password. Please Try Again.", , "Incorrect Password"
    End If
    End Sub

    Thanks for all the help.. i'm sure I'll have some more questions in a lil bit

    please check my other problem about parameter values just poppin up

Posting Permissions

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