DELETE Record in Database

S

shapper

Hello,

I created a Query in and Access database to delete a record.
However I need to return something if the record was found or not.

How can I do this?

My Query is:
DELETE *
FROM web_MailingList
WHERE web_MailingList.SubscriberEmail=[@SubscriberEmail];

Should I have two queries?
What I mean is should I first try to load the record where
"SubscriberEmail=[@SubscriberEmail];" and if it does not return a
record I would not use the Query Delete.
This does not sound a good approach.

Basically I woul prefer to use only one Query.

Thanks,
Miguel
 
B

Brendan Reynolds

If you execute the query via code you can check the RecordsAffected property
(DAO) or RecordsAffected argument (ADO). Here are examples ...

Public Sub TestDelete()

'Using DAO.

Dim db As DAO.Database
Dim lngRecords As Long

Set db = CurrentDb
db.Execute "DELETE FROM tblTest WHERE TestID = 5"
lngRecords = db.RecordsAffected
Debug.Print lngRecords & " record(s) where deleted using DAO."

'Using ADO.

Dim cn As ADODB.Connection
Set cn = CurrentProject.Connection
cn.Execute "DELETE FROM tblTest WHERE TestID = 6", lngRecords
Debug.Print lngRecords & " record(s) where deleted using ADO."

End Sub
 

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