Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Delete current record

Author(s)
Dev Ashish &
Andy Baron

    If you don't like the DoMenuItem code that the Button Wizard creates for Delete Record, you can use this function instead.

    To call the function, put this or similar code behind a button.

Private Sub DeleteCurrentRecord_Click()
    If Not (fDelCurrentRec(Me)) Then
        MsgBox "An Error occurred!"
    End If
End Sub

 

The actual function is:

'************** Code Start *************
Function fDelCurrentRec(ByRef frmSomeForm As Form) As Boolean
    On Error GoTo Err_Section
    
    With frmSomeForm
        If .NewRecord Then
            .Undo
            fDelCurrentRec = True
            GoTo Exit_Section
        End If
    End With
    
    With frmSomeForm.RecordsetClone
        .Bookmark = frmSomeForm.Bookmark
        .Delete
        frmSomeForm.Requery
    End With
    fDelCurrentRec = True
Exit_Section:
    Exit Function

Err_Section:
    fDelCurrentRec = False
    Resume Exit_Section
End Function
'************** Code End *************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer