EOF not working - using find record routine

G

Guest

I have this routine to get to a particular record base on a value entered
into a text box. This value is compared to a field value [RecNo] to get the
matching record. I am OK when entering a value that the routine can find,
but if I enter a nonexitent value, it always goes to the first record (which
also happens to have a RecNo = 1).
Another question I have is that I don't understand the "rs.edit" that I seem
to need, or I get an error message regarding "Update or CancelUpdate without
AddNew or Edit"

The routine I created is:

Private Sub FindIt_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.Edit
rs.FindFirst "[RecNo] = " & Str(Nz(Me![FindIt], 0))

Debug.Print [RecNo]
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "You entered a nonexitent record number", vbExclamation,
"Warning"
bytNoRec = True
Me!SeqNo.SetFocus
Me!FindIt.SetFocus
Me!FindIt = Null
rs.Close
Set rs = Nothing
Exit Sub
End If
End Sub

Thanks for any help. You can also email any help to: photopro at (leave
this out) cox dot net.
 
S

Stefan Hoffmann

hi Issac,
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.Edit Edit?

rs.FindFirst "[RecNo] = " & Str(Nz(Me![FindIt], 0))

Debug.Print [RecNo]
If Not rs.EOF Then
Use
If Not rs.NoMatch Then ...
Me.Bookmark = rs.Bookmark
Else
MsgBox "You entered a nonexitent record number", vbExclamation,
"Warning"
End If
End Sub


mfG
--> stefan <--
 
K

Keith Wilby

Isaac said:
I have this routine to get to a particular record base on a value entered
into a text box. This value is compared to a field value [RecNo] to get
the
matching record. I am OK when entering a value that the routine can find,
but if I enter a nonexitent value, it always goes to the first record
(which
also happens to have a RecNo = 1).
Another question I have is that I don't understand the "rs.edit" that I
seem
to need, or I get an error message regarding "Update or CancelUpdate
without
AddNew or Edit"

The routine I created is:

Try something like this:

Dim rs As DAO.Recordset

Dim strFindIt As String
strFindIt = InputBox("Enter a number")
If strFindIt = "" Then Exit Sub

Set rs = Me.RecordsetClone
rs.FindFirst "[RecNo] = " & strFindIt

If Not rs.NoMatch Then
Debug.Print rs("RecNo")
Me.Bookmark = rs.Bookmark
Else
MsgBox "You entered a nonexitent record number", vbExclamation,
"Warning"
Exit Sub
End If

rs.Close
Set rs = Nothing

Regards,
Keith.
www.keithwilby.com
 
G

Guest

Thank you both for your suggestions. They solve the problem. I am still
curious, though as to why what I did doesn't work, and what the "Updatae or
candelUpdate ... " is all about. Just curious. Again, thanks.
 

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

Top