Multiple Delete Statements

G

Guest

Hello;

I am writing the following VBA code that will enable a user to delete
records from 2 tables (Children + Parent). Then I would like the form to
update. This is what I have.

Any suggestions would be much appreciated.



' MsgBox asking the user if 'Y/N' they would like to delete

If Response = vbYes Then ' User chose Yes.

'Delete Children
strSQL = "DELETE * " & _
"FROM tblTariffs " & _
"WHERE RPID = " & Me.RPID

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL

'Delete Parent

strSQL = "DELETE *" & _
"FROM tblRePrice " & _
"WHERE RPID =" & Me.RPID

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL

Else ' User chose No.

Exit Sub

End If

'Update Form

strSQL = "SELECT RPID, ClientName AS [Client Name], VerifiedDate AS
Verified " & _
"FROM tblRePrice " & _
"GROUP BY RPID, ClientName, VerifiedDate " & _
"ORDER BY ClientName, VerifiedDate;"

DoCmd.RunSQL strSQL
Me.f_Options.Value = 1
 
G

Guest

If you want the form to refresh it self after you delete a record, just use

me.requery

Assuming that you have more records to be displayed.

Or if you want to change the recordsource with the new sql, then use that

strSQL = "SELECT RPID, ClientName AS [Client Name], VerifiedDate AS
Verified " & _
"FROM tblRePrice " & _
"GROUP BY RPID, ClientName, VerifiedDate " & _
"ORDER BY ClientName, VerifiedDate;"

' DoCmd.RunSQL strSQL No need to run the sql
Me.recordsource = strSQL
Me.f_Options.Value = 1
 

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