Search button on form

  • Thread starter Thread starter Allan Murphy
  • Start date Start date
A

Allan Murphy

Do you have a unique field that identifies the record e.g record_ref as an
autonumber?

Try this code
Private Sub SearchBatter_Click()

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[record_ref] = " & str(Me![NameDropDown])
Me.Bookmark = rs.Bookmark
end sub
 
I have a form that is bound to a query. When I first open up the form, the
form displays fields from the first record.

On the same form, I have a drop down (NameDropDown) and a command button
(SearchBatter). What I want to happen is when the user selects an item from
the drop down and clicks the command button, I want the form to display the
fields that relate to the value in the drop down.

I have the following code in the Click event of the command button:

Private Sub SearchBatter_Click()
Dim strWhere As String
Dim strName As String

strName = Me.NameDropDown
strWhere = "([Name] = """ & strName & """)"
Me.Filter = strWhere
Me.FilterOn = True
End Sub

When I select a value from the drop down and click the button, nothing
changes in the form.

Can you help?
 
I tried this but I got the same result. It's like clicking on the Search
button is doing nothing.

Allan Murphy said:
Do you have a unique field that identifies the record e.g record_ref as an
autonumber?

Try this code
Private Sub SearchBatter_Click()

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[record_ref] = " & str(Me![NameDropDown])
Me.Bookmark = rs.Bookmark
end sub

Shael said:
I have a form that is bound to a query. When I first open up the form, the
form displays fields from the first record.

On the same form, I have a drop down (NameDropDown) and a command button
(SearchBatter). What I want to happen is when the user selects an item from
the drop down and clicks the command button, I want the form to display the
fields that relate to the value in the drop down.

I have the following code in the Click event of the command button:

Private Sub SearchBatter_Click()
Dim strWhere As String
Dim strName As String

strName = Me.NameDropDown
strWhere = "([Name] = """ & strName & """)"
Me.Filter = strWhere
Me.FilterOn = True
End Sub

When I select a value from the drop down and click the button, nothing
changes in the form.

Can you help?
 
Back
Top