Is this code 100% reliable or are there circumstances under which it could fail? I seem to have an obscure bug where very occasionally records that match the SQL are not being deleted. Is "MoveNext" inside the loop sufficient or should I start with "MoveFirst" before the loop? Is there a better way to delete records?
Code:
Sub Delete_Record
Call OpenDB("Select * from tblInvoiceLines where tblInvoiceLines.InvoiceID = " & GlInvoiceID)
With GrsVet
Do While Not .EOF
.Delete
.MoveNext
Loop
.Close
End With
End Sub
Sub OpenDB(SQL As String)
Set GcnVet = New adodb.Connection
GcnVet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & GsDBpath & ";Jet OLEDB:Database Password=**********"
GcnVet.Open
Set GrsVet = New adodb.Recordset
GrsVet.CursorLocation = adUseClient
GrsVet.Open SQL, GcnVet, adOpenKeyset, adLockPessimistic
End Sub