By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

Cannot Cancel Delete

P: n/a
I have added a delete control to my form with code in the On Click
property. The delete works well, but if I cancel the delete action,
the record is still deleted.

Here's the code:

MsgBox "Confirm delete. Once you confirm, the record will no longer
exist.", vbOKCancel
strSQL = "DELETE FROM TOrdAck WHERE OANo=" & Me!OANo
Set dbs = CurrentDb
dbs.Execute strSQL, dbFailOnError
MsgBox dbs.RecordsAffected & " record(s) deleted"

What's missing?

Jul 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Use the MsgBox() function, and examine the value it returns:

If MsgBox( "Confirm delete. Once you confirm, the record will no longer
exist.", vbOKCancel) = vbOk Then
strSQL = "DELETE FROM TOrdAck WHERE OANo=" & Me!OANo
Set dbs = CurrentDb
dbs.Execute strSQL, dbFailOnError
MsgBox dbs.RecordsAffected & " record(s) deleted"
End If

BTW, if this is a bound form, you don't need to execute the Delete query.
Just:
RunCommand acCmdDeleteRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Swinky" <sw********@lunt.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
>I have added a delete control to my form with code in the On Click
property. The delete works well, but if I cancel the delete action,
the record is still deleted.

Here's the code:

MsgBox "Confirm delete. Once you confirm, the record will no longer
exist.", vbOKCancel
strSQL = "DELETE FROM TOrdAck WHERE OANo=" & Me!OANo
Set dbs = CurrentDb
dbs.Execute strSQL, dbFailOnError
MsgBox dbs.RecordsAffected & " record(s) deleted"

What's missing?
Jul 18 '07 #2

P: n/a
On Jul 18, 9:19 am, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Use the MsgBox() function, and examine the value it returns:

If MsgBox( "Confirm delete. Once you confirm, the record will no longer
exist.", vbOKCancel) = vbOk Then
strSQL = "DELETE FROM TOrdAck WHERE OANo=" & Me!OANo
Set dbs = CurrentDb
dbs.Execute strSQL, dbFailOnError
MsgBox dbs.RecordsAffected & " record(s) deleted"
End If

BTW, if this is a bound form, you don't need to execute the Delete query.
Just:
RunCommand acCmdDeleteRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Thanks Allen, worked like a charm!

As a side note, I was using the acCmdDeleteRecord and had a funky
problem. The record would look like it was deleted when clicking the
delete control (the record disappeared). However, when I exited the
form & reopened it, the deleted record was there again. I thought
this might be because there were several subforms related to the main
form so I used the Delete query in place of acCmdDeleteRecord and
bingo, my problem solved (except for the cancel option which you have
helped me to fix). Thanks!
Jul 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.