Find First

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
 
L

Linq Adams via AccessMonster.com

The first question that has to be asked is what kind of control is Command33?


A control name starting with Command is normally a Command Button. Command
Buttons do not have a value and thus cannot be Null or not Null, and cannot
be used in something like

"[Descr2] = """ & Me.Command33 & """"
 
M

Marshall Barton

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
 
J

John Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Finding First then Next 5
Bookmark Issue 7
Run-time error '424' 2
Find Method not working properly 10
FindFirst 3
How to update control 3
List Box on main form 5
Data type conversion error 0

Top