FindFirst quit working

C

Cheryl Bender

I am completely stumped. This was working yesterday.

The code searches for the barcode entered to confirm it is associated
with a required record. What is happening now is that FindFirst
returns a record that doesn't match the one searched and returns EOF =
false. I have tried decompiling, moving the code to a different
module, compact and repair, but cannot explain this behavior. If I
take the where statement and put it in a query it returns no records
(which it should since the barcode is not associated) but when I do
FindFirst it returns the wrong record. I have other code in the same
database that uses FindFirst and seems to be working fine. The only
thing I can think to do is add code that will verify the record found
matches the one searched, but it just doesn't seem right. Thanks.

Public Function CheckVial(pstrVial As String, pstrLot As String,
pstrCASNo As String) As Boolean
On Error GoTo CheckVial_Err

Dim recCheckVial As Recordset
Set recCheckVial = CurrentDb.OpenRecordset("qryVialBarcodeCASNo")
recCheckVial.FindFirst "Vialbarcode = """ & pstrVial & """"
If Not recCheckVial.EOF Then
pstrLot = recCheckVial!lot
pstrCASNo = recCheckVial!CASNo
CheckVial = True
Else
CheckVial = False

End If

.....'error handling code removed
End Function
 
C

Cheryl Bender

Thanks Marsh--I knew I must be having a brain cramp and that was
it.

Cheryl said:
I am completely stumped.  This was working yesterday.
The code searches for the barcode entered to confirm it is associated
with a required record.  What is happening now is that FindFirst
returns a record that doesn't match the one searched and returns EOF =
false.    I have tried decompiling, moving the code to a different
module, compact and repair, but cannot explain this behavior.  If I
take the where statement and put it in a query it returns no records
(which it should since the barcode is not associated) but when I do
FindFirst it returns the wrong record.  I have other code in the same
database that uses FindFirst and seems to be working fine.  The only
thing I can think to do is add code that will verify the record found
matches the one searched, but it just doesn't seem right.  Thanks.
Public Function CheckVial(pstrVial As String, pstrLot As String,
pstrCASNo As String) As Boolean
    On Error GoTo CheckVial_Err
   Dim recCheckVial As Recordset
   Set recCheckVial = CurrentDb.OpenRecordset("qryVialBarcodeCASNo")
   recCheckVial.FindFirst "Vialbarcode = """ & pstrVial & """"
   If Not recCheckVial.EOF Then
       pstrLot = recCheckVial!lot
       pstrCASNo = recCheckVial!CASNo
       CheckVial = True
   Else
       CheckVial = False
   End If

It looks like you started by using the stupid Find Record
wizard's generated code.  Change the line:

   If Not recCheckVial.EOF Then

to this:

   If Not recCheckVial.NoMatch Then

The EOF check is the ADO way to check for not found, but the
DAO way is to use the NoMatch property.  If you don't what
that means, just remember it for future reference.

--
Marsh
MVP [MS Access]- Hide quoted text -

- Show quoted text -
 

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


Top