Find Last Record matching specific criteria

G

Guest

I'm trying to use the Find method for the first time and am getting run-time
error 3001. (Recent post from a different user did not solve my problem.)

Any idea what I'm doing wrong here?


Set conEvent = CurrentProject.Connection
Set rstEvent = New Recordset
With rstEvent
.Source = "Select * from Event"
.ActiveConnection = conEvent
.LockType = adLockOptimistic
.Open
.MoveLast
.Find "Event Type ='24'", , adSearchBackward
intEventId = ![Event ID].Value
End With
 
J

J. Goddard

Hi -

First, Event type should be in square brackets, because it contains a
space: [Event Type]

What data type is [Event type]? It is is numeric, then you don't need
the quotes around the 24.

I think you want to use the FindLast method, not the Find method,
because you are using criteria:

..findLast "[event type] = 24" or .findLast "[event type] = '24'"


HTH

John
 
G

Guest

John, thanks for correcting my brackets and quotes. I always get that
confused; with those changes, I no longer got the 3001 error.

For whatever reason, Access wouldn't let me use the .FindLast method (got a
compile error saying that method was not found) and .Find continued to behave
erratically (not finding a record that I KNEW was there, and giving me a
different run-time error, something like ".eof or .bof found, choose a
different recordset."

So, I worked around it by using .Filter and .MoveLast instead of .Find:

.Filter = "[Event Type]=24"
.MoveLast


J. Goddard said:
Hi -

First, Event type should be in square brackets, because it contains a
space: [Event Type]

What data type is [Event type]? It is is numeric, then you don't need
the quotes around the 24.

I think you want to use the FindLast method, not the Find method,
because you are using criteria:

..findLast "[event type] = 24" or .findLast "[event type] = '24'"


HTH

John



I'm trying to use the Find method for the first time and am getting run-time
error 3001. (Recent post from a different user did not solve my problem.)

Any idea what I'm doing wrong here?


Set conEvent = CurrentProject.Connection
Set rstEvent = New Recordset
With rstEvent
.Source = "Select * from Event"
.ActiveConnection = conEvent
.LockType = adLockOptimistic
.Open
.MoveLast
.Find "Event Type ='24'", , adSearchBackward
intEventId = ![Event ID].Value
End With
 

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