Find First

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I am having trouble making this work. I am trying to do a find in a subform.

Dim rs As DAO.Recordset

If Not IsNull(Me.Command33) Then
Set rs = Forms![fAddGroupCat]![fAddGroupCatSub2].[Form].RecordsetClone
rs.FindFirst "[Descr2] = """ & Me.Command33 & """"
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If


Thank you,

Steven

Also: How can you tell it to start at the last record and find looking back
up?


Thank you,

Steven
 
Where are you running this code?
This line
Set rs = Forms![fAddGroupCat]![fAddGroupCatSub2].[Form].RecordsetClone
makes me think that you are executing the code in the main form instead of in
the subform.

If that is true then this line
Me.Bookmark = rs.Bookmark
is probably wrong. Since it would be setting the main form's bookmark equal
to the subform's bookmark.

So perhaps you want
Forms![fAddGroupCat]![fAddGroupCatSub2].[Form].Bookmark = rs.Bookmark

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Marshall said:
Steven said:
I am having trouble making this work. I am trying to do a find in a subform.

Dim rs As DAO.Recordset

If Not IsNull(Me.Command33) Then
Set rs = Forms![fAddGroupCat]![fAddGroupCatSub2].[Form].RecordsetClone
rs.FindFirst "[Descr2] = """ & Me.Command33 & """"
If rs.NoMatch Then
MsgBox "Not found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If

Also: How can you tell it to start at the last record and find looking back
up?


If Command33 is a text box, then it should work.

If you want to start at the end of the recordset, use
FindLast instead of FindFirst
 
Back
Top