Undo subform delete

  • Thread starter Thread starter ExcelMan
  • Start date Start date
E

ExcelMan

I have a command button on a form that I use to delete the current record in
a subform.

The code behind the button is:

Forms(Me.Name)("subformname").Form.Recordset.Delete


What I want to do is pop up the Delete confirm dialog box that Access
automatically pops up when the user deletes a selected record by hitting the
DELETE key. But the code above does not seem to trigger any events in the
subform -- specifically the On Delete or Before Del Confirm events -- for me
to trap the delete, msg the user, and if appropriate, cancel the delete
action.

Any ideas how to do this?

Thanks.
 
Hi ExcelMan,

Here's the sample code you want to use

Private Sub Command6_Click()
Dim response
response = MsgBox("you want to delete?", vbYesNo, "deleting record")
If response = vbYes Then
With Me.[your subForm control].Form.RecordsetClone
.Bookmark = Me.[your subForm control].Form.Bookmark
.Delete
End With
Me.[your subForm control].Requery
Else
End If
End Sub


I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights


--------------------
| From: "ExcelMan" <sjfarkas@csi.com>
| Newsgroups: microsoft.public.access.formscoding
| Subject: Undo subform delete
| Date: Wed, 22 Sep 2004 15:03:48 -0700
| Organization: CompuServe Interactive Services
| Lines: 20
| Message-ID: <ciss9r$42p$1@ngspool-d02.news.aol.com>
| NNTP-Posting-Host: sfr-tgn-sfv-vty14.as.wcom.net
| X-Trace: ngspool-d02.news.aol.com 1095890044 4185 216.192.40.14 (22 Sep
2004 21:54:04 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Wed, 22 Sep 2004 21:54:04 +0000 (UTC)
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwi
x.com!newsfeed.cwix.com!border1.nntp.dca.giganews.com!nntp.giganews.com!ngpe
er.news.aol.com!news.compuserve.com!news-master.compuserve.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.access.formscoding:246883
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| I have a command button on a form that I use to delete the current record
in
| a subform.
|
| The code behind the button is:
|
| Forms(Me.Name)("subformname").Form.Recordset.Delete
|
|
| What I want to do is pop up the Delete confirm dialog box that Access
| automatically pops up when the user deletes a selected record by hitting
the
| DELETE key. But the code above does not seem to trigger any events in the
| subform -- specifically the On Delete or Before Del Confirm events -- for
me
| to trap the delete, msg the user, and if appropriate, cancel the delete
| action.
|
| Any ideas how to do this?
|
| Thanks.
|
|
|
 
Put the following code behind your button:

Dim MsgStr As String
Dim TitleStr As Str
MsgStr = "Are You Sure You Want To Delete ...." ' Or what ever you want
TitleStr = "....." 'Whatever you want!
If MsgBox(MsgStr,vbYesNo, TitleStr) = vbYes Then
Forms(Me.Name)("subformname").Form.Recordset.Delete
End If
 
Back
Top