On Enter key dont want to loose focus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ykhamitkar
    New Member
    • May 2007
    • 64

    On Enter key dont want to loose focus

    Hi there,

    I have a textfield for some search option in the ms access form
    I have written a code that after typing the search text as soon as user hits Enter key the data form puts some filter on the table
    However focus goes to some other control

    I would like the focus to be on the same text box even if the user hits Enter key

    my code is
    Private Sub txt_Filter_Coun terpartyName_Ke yDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
    put_filter
    txt_Filter_Coun terpartyName.Se tFocus
    End If
    End Sub

    Please advice

    Yogesh
  • PianoMan64
    Recognized Expert Contributor
    • Jan 2008
    • 374

    #2

    Hi there,

    I have a textfield for some search option in the ms access form
    I have written a code that after typing the search text as soon as user hits Enter key the data form puts some filter on the table
    However focus goes to some other control

    I would like the focus to be on the same text box even if the user hits Enter key

    my code is
    Private Sub txt_Filter_Coun terpartyName_Ke yDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
    put_filter
    txt_Filter_Coun terpartyName.Se tFocus
    End If
    End Sub

    Please advice

    Yogesh
    Yogesh,

    I'm going to assume for the moment, that the data that you're displaying on the form is a ListControl? and the textfield that you're speaking about is the only field on the form?

    If both of those answer are true, then here is what you're going to need to do:

    1. Find out what the name of the list control is?
    2. Once you find it, Rename it to MyListControl
    3. Locate the TextField Control.
    3. Rename it to Criteria
    4. Create a button control on the form next to Textfield control and call it SearchBtn
    5. Right-click on the Button Control and select properties of the list.
    6. Scroll down until you get to the event On_Click
    7. Press the ... Button on the right side of the dialog box.
    8. Select Code Editor
    9. type of following code for your list control:

    [Code=VB]

    Function SearchBtn_Click ()
    Me.MyControlLis t.RowSourceType = "Table/Query"
    Me.MyControlLis t.RowSource = "SELECT * FROM {TableName} WHERE {FilterFieldNam e}='" & Me.Criteria.Val ue & "'"
    'please name sure to replace {TableName} with the name of the table that you're using and also the {FilterFieldNam e} with the field name that is in the able that you're searching by.
    Me.MyControlLis t.Requery
    Me.Repaint
    End Function

    [/code]

    Hope that helps,

    Joe P.

    Comment

    Working...