Delete Records based on DoCmd.RunSQL

D

davea

Hi

I have a command button that when clicked deletes certain records from
a subform based on an application number being equal. It deletes all
records with the same applciation number as currently shown on the
main form, see code below:

DoCmd.RunSQL ("DELETE FROM tblAdultDetails WHERE
[frmAdultDetails2].Form![ApplicationNum]=" +
Str(Me.ApplicationNumber))

However I would like it to only delete records if the fields
[MainApplicantFlag] =1 or [PartnerFlag] =1 as well as ApplicationNum
being equal. These are both number fields btw.

Can someone tell me what I should add to my code in order to do this?
I'm not sure of the syntax.

Thanks
 
A

Allen Browne

Try this:

Dim strSql As String
strSql = "DELETE FROM tblAdultDetails WHERE ((tblAdultDetails.[Field1] = " &
Me.ApplicationNumber & ") AND ((tblAdultDetails.[MainApplicantFlag] =1) OR
(tblAdultDetails.[PartnerFlag] = 1)));
dbEngine(0)(0).Execute strSql, dbFailOnError

Replace "Field1" with the name of the field in the table that matches the
application number.

Using the Execute method, you can know whether the deletion succeeded or
not. For more about that, see:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
 

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