Findfirst and delete (DAO) 
Author Message
 Findfirst and delete (DAO)

I'm having problems with FindFirst and Delete methods in VB 5.0
I need to find record in recordset and delete this record.
Program finds record, but delete the first record in recordset instead
of found record.
Can you help me?
There is a code

With datFeature.Recordset
   .FindFirst "FeatureID='" & strFeatureID & "'"
   If Not .NoMatch Then
       .Delete
       datFeature.Refresh
   End If
End With

--
Best regards,
Michael

Sent via Deja.com http://www.***.com/
Share what you know. Learn what you don't.



Mon, 17 Dec 2001 03:00:00 GMT
 Findfirst and delete (DAO)

Well Michael,
I'm not real sure what is going wrong, but this long section
of code is what works for me. Mine is designed to do the DAO
delete of a record found from data received from a DOS
machine via RS-232, but I think it may help. I wouldn't send
it otherwise.
----------------------------------
'open database
Set db = DAO.DBEngine.OpenDatabase(dbPath)
If (Err.Number = 0) Then
    Dim rs As DAO.Recordset
    Dim RecCount As Long

    Set rs = db.OpenRecordset(SQ, dbOpenDynaset)
    If (Err.Number = 0) Then
rs.MoveLast
RecCount = rs.RecordCount
txtLineComms(Poll).Text = RecCount
rs.MoveFirst
Dim SearchItem As String
SearchItem = "LebNum = '" & LebNum & "'"
        rs.FindFirst SearchItem

        If Not rs.NoMatch Then
            If Shift = rs.Fields(10).Value And DateDiff("h",
Now, rs.Fields(33).Value) = 0 Then
                rs.Delete
                MSComm1.Output = LebNum & " Deleted!" & vbCr
            Else
                MSComm1.Output = LebNum & " Access Not
Authorized!" & vbCr
            End If
        Else
            MSComm1.Output = LebNum & " record not found." &
vbCr
        End If

    Else
            MSComm1.Output = "Error opening rs. Call 137." &
vbCr
    End If

End If

' Close records up
rs.Close
Set rs = Nothing

' Close database
db.Close
Set db = Nothing
End Sub
----------------------------------

To be honest, I don't really see any difference between your
code and mine. In the heart of it anyway.

Quote:

>I'm having problems with FindFirst and Delete methods in VB
5.0
>I need to find record in recordset and delete this record.
>Program finds record, but delete the first record in
recordset instead
>of found record.
>Can you help me?
>There is a code

>With datFeature.Recordset
>   .FindFirst "FeatureID='" & strFeatureID & "'"
>   If Not .NoMatch Then
>       .Delete
>       datFeature.Refresh
>   End If
>End With

>--
>Best regards,
>Michael

>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.



Mon, 17 Dec 2001 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. problems using DAO FindFirst from outllook

2. Searching with ADO (What is the equivalent of the DAO FindFirst method)

3. DAO: FindFirst Problem

4. DAO - Findfirst criteria

5. DAO FindFirst/FindNext question???

6. DAO 3.6 and FindFirst Method (Error 3251)

7. ADO find method compare with DAO findfirst method...

8. Q: DAO FindFirst crashes KERNEL32 (undocumented restrictions?)

9. ADO substitute for DAO FindFirst

10. Findfirst method and DAO 3.6/Jet 4.0

11. DAO - FindFirst criteria

12. FindFirst in DAO


 
Powered by phpBB® Forum Software