Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009

    Unanswered: Search Button to Find Specific Record

    I have created a form with several bound text boxes, linked to tables/queries, and one of the main text boxes is Customer ID. I have created a button on this form called, 'Find Customer'. Once this button is selected, I would like the operator to enter a customer ID and then the record related to the Customer ID appears on the form. The Customer ID is a unique number.

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 15
    Let's suppose that you have an unbound textbox names Text_1 and a button named Button_1 on your form, and that your form is linked to a table or a query where there is a column with a unique ID: SysCounter.

    In the OnClick event of the button add this code:

    Private Sub Button_1_Click()
        Dim rst As DAO.Recordset    ' Don't forget to add a reference to DAO
        Dim strCriteria As String
        If Not IsNull(Me.Text_1.Value) Then
            strCriteria = "SysCounter = " & Me.Text_1.Value
            Set rst = Me.RecordsetClone
            rst.FindFirst strCriteria
            If rst.NoMatch Then
                MsgBox "Cannot find record " & Me.Text_1.Value
                Me.Bookmark = rst.Bookmark
            End If
            Set rst = Nothing
        End If
    End Sub
    You can also use a combo box and spare the button. See:
    Forms: Have the form move to the record selected in List/Combo box

    Have a nice day!

  3. #3
    Join Date
    Mar 2009
    Many thanks for your response. Kind regards.

Posting Permissions

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