Display Record(s) based on selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combo box in the header section of a form, I have the code below in
the after update event to find the record that goes with the item selected in
the combo box. The problem is, some of the selections will have more than
one record associated with them. With the form in normal view it's fine for
the ones that only have one record, but on those with multiple records, it
will only show the first one. Which makes sense because I'm using FindFirst.
When I put the form in continuous view, which is actually the way I want it-
it displays all the records not just the ones matching the combo selection.
I'm sure there is something else I need to use here besides FindFirst, but I
don't know what. How can I make it display all the records associated with
the selection in the combo box??? The form is based on a query if that
matters.

Public Sub cboLabName_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.Recordset.Clone

rst.FindFirst "[Lab Name] = '" & Me![cboLabName] & "'"

Me.Bookmark = rs.Bookmark

Me.Detail.Visible = True

End Sub

Any ideas would be greatly appreciated, Thanks.
 
rg32 said:
I have a combo box in the header section of a form, I have the code
below in the after update event to find the record that goes with the
item selected in the combo box. The problem is, some of the
selections will have more than one record associated with them. With
the form in normal view it's fine for the ones that only have one
record, but on those with multiple records, it will only show the
first one. Which makes sense because I'm using FindFirst. When I
put the form in continuous view, which is actually the way I want it-
it displays all the records not just the ones matching the combo
selection. I'm sure there is something else I need to use here
besides FindFirst, but I don't know what. How can I make it display
all the records associated with the selection in the combo box???
The form is based on a query if that matters.

Public Sub cboLabName_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.Recordset.Clone

rst.FindFirst "[Lab Name] = '" & Me![cboLabName] & "'"

Me.Bookmark = rs.Bookmark

Me.Detail.Visible = True

End Sub

Any ideas would be greatly appreciated, Thanks.

You could filter the form to display only the matching record(s), rather
than navigating to find them. Code would look like this:

'----- start of code -----
Public Sub cboLabName_AfterUpdate()

If IsNull(Me!cboLabName) Then
Me.FilterOn = False
Me.Filter = ""
Else
Me.Filter = "[Lab Name] = '" & Me![cboLabName] & "'"
Me.FilterOn = True
End If

End Sub

'----- end of code -----
 
Back
Top