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_CounterpartyName_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
put_filter
txt_Filter_CounterpartyName.SetFocus
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:
-
-
Function SearchBtn_Click()
-
Me.MyControlList.RowSourceType = "Table/Query"
-
Me.MyControlList.RowSource = "SELECT * FROM {TableName} WHERE {FilterFieldName}='" & Me.Criteria.Value & "'"
-
'please name sure to replace {TableName} with the name of the table that you're using and also the {FilterFieldName} with the field name that is in the able that you're searching by.
-
Me.MyControlList.Requery
-
Me.Repaint
-
End Function
-
-
Hope that helps,
Joe P.