Hi all,
Should be a simple one. I have the following code that finds a record in a table, and deletes it (only if the 'Deleted' condition is true) -
If Deleted = True Then
strCriteria = "[ID] = " & EnquiryNumber
Set ADOrs = New ADODB.Recordset
ADOrs.ActiveConnection = CurrentProject.Connection
ADOrs.Open "tblMissingPayment", , adOpenKeyset, adLockOptimistic
With ADOrs
.Find strCriteria
.Delete
.Update
.Close
End With
Set ADOrs = Nothing
End If
In some instances, strCriteria may not exist in the table and I am not sure what code to use to handle this.
i.e.
If strCriteria exists in tblMissingPayment Then
.Delete
.Update
.Close
Else
.Close
End If
Could someone point me in the right direction please?
Thanks
Robert
EDIT: I have got around this by using a DLookup to check if the ID exists, if the Dlookup variable isNull - then do nothing, else perform the above function. If there is a better way though without DLookup I am keen to learn it! Thanks
Should be a simple one. I have the following code that finds a record in a table, and deletes it (only if the 'Deleted' condition is true) -
If Deleted = True Then
strCriteria = "[ID] = " & EnquiryNumber
Set ADOrs = New ADODB.Recordset
ADOrs.ActiveConnection = CurrentProject.Connection
ADOrs.Open "tblMissingPayment", , adOpenKeyset, adLockOptimistic
With ADOrs
.Find strCriteria
.Delete
.Update
.Close
End With
Set ADOrs = Nothing
End If
In some instances, strCriteria may not exist in the table and I am not sure what code to use to handle this.
i.e.
If strCriteria exists in tblMissingPayment Then
.Delete
.Update
.Close
Else
.Close
End If
Could someone point me in the right direction please?
Thanks
Robert
EDIT: I have got around this by using a DLookup to check if the ID exists, if the Dlookup variable isNull - then do nothing, else perform the above function. If there is a better way though without DLookup I am keen to learn it! Thanks
Last edited: