none
Multi-Textbox Search Forum - On Enter Behavior RRS feed

  • Question

  • I have a search form with two text boxes . If the user knows the phone number for the record they are searching (or partial) they can enter in the phone number and clock search by phone..

    the second one is the same for company name.

    I would like the user to be able to enter in the characters in either text box and hit ENTER to fire off the query . As of now they have to mouse click or touch the button located underneath the text box (btnPhone and btnCompany)

    On the form properties I do not see an On Enter event.

    Can someone help? thanks Andrew

    Monday, February 13, 2017 6:15 PM

Answers

  • I would like the user to be able to enter in the characters in either text box and hit ENTER to fire off the query . As of now they have to mouse click or touch the button located underneath the text box (btnPhone and btnCompany)

    Hi Andrew,

    In the KeyPress event of the control you can inspect which key is pressed. When this is the Enter key (vbKeyReturn, 13), then you can invoke the procedure of the button (that is used now).

    Imb.

    Tuesday, February 14, 2017 7:59 AM

All replies

  • Hi ,

    I understand your requirement clearly.

    I have done this before.

    I know that you are using textbox here.

    but you can see that there are multiple records are available in the database that can match and using textbox it is not possible to view that all the possible records.

    so here I suggest you to use combobox.

    so that when you fetch all the possible matches from the database then you can display it using combo box.

    and user can choose the correct choice from that.

    below is an example for that.

    Private Sub CM_Change()
    Dim str, str2 As String
       Dim dbs As Database, rst As Recordset
     str2 = Me.CM.Text & "*"
    With Me.CM
        .RowSourceType = "Value List"
        .RowSource = ""
      End With
        
        Set dbs = CurrentDb
     
        Set rst = dbs.OpenRecordset("SELECT Country FROM tblCountry1 where Country like '" & str2 & "' ;")
     
       Do While Not rst.EOF
    str = rst.Fields("Country").Value
    Debug.Print str
      Me.CM.AddItem (str)
     rst.MoveNext
    Loop
    End Sub

    Output:

    you can try to modify it as per your requirement.

    Reference:

    Alert me filtering ms access combobox

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, February 14, 2017 2:44 AM
    Moderator
  • I would like the user to be able to enter in the characters in either text box and hit ENTER to fire off the query . As of now they have to mouse click or touch the button located underneath the text box (btnPhone and btnCompany)

    Hi Andrew,

    In the KeyPress event of the control you can inspect which key is pressed. When this is the Enter key (vbKeyReturn, 13), then you can invoke the procedure of the button (that is used now).

    Imb.

    Tuesday, February 14, 2017 7:59 AM
  • Thank you so much Imb. This is exactly what I am looking for. I appreciate your help so much.

    Andrew

    Tuesday, February 14, 2017 2:14 PM
  • Deepak,

    Thank you for your assistance. I will use this technique to solve another issue I am having. I appreciate your help

    Andrew

    Tuesday, February 14, 2017 2:14 PM
  • You can try this.

    Private Sub ComboSelect_Change()
    
        '  You need to use String delimiters if you want to use a Text Field like:
        '  Me.Filter "[ATextFieldInRecordSource] = """ & Me.FilterComboBox & """"
    
        '  For a Numeric Field, use something like this:
        '  Me.Filter "[ANumericFieldInRecordSource] = " & Me.FilterComboBox
        '  Me.FilterOn = True
    
        Me.[Customer_Query subform1].Form.Filter = "[Company_Name] Like '*" &
                         Replace(Me.ComboSelect.Text, "'", "''") & "*'"
        Me.[Customer_Query subform1].Form.FilterOn = True
    
    End Sub
    


    Notice a few things:

    • The subform is named Customer_Query subform1’
    • The combobox is named ComboSelect’
    • Finally, the ‘like clause’ is used in combination with the wildcard character.
    • Like '*" & Replace(Me.ComboSelect.Text, "'", "''") & "*'"


     

    When you type text into the combobox, the results in the subform are dynamically re-queried.


    MY BOOK

    Thursday, February 16, 2017 11:55 PM