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.
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
If rst.NoMatch Then
MsgBox "Cannot find record " & Me.Text_1.Value
Me.Bookmark = rst.Bookmark
Set rst = Nothing