If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > PC based Database Applications > Microsoft Access > Search Button to Find Specific Record

LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Registered User
Join Date: Mar 2009
Posts: 11
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.
Reply With Quote
  #2 (permalink)  
Join Date: Mar 2009
Posts: 5,202
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!
Reply With Quote
  #3 (permalink)  
Registered User
Join Date: Mar 2009
Posts: 11
Many thanks for your response. Kind regards.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On