Full Version: Delete record sub used on form
UtterAccess Discussion Forums > Microsoft® Access > Access Modules
alton
Someone please, please tell me what's wrong with this!! It just doesn't work!

CODE
Private Sub DeleteEntry_Click()
On Error GoTo Err_DeleteEntry_Click

If Me!SentToAccounts = True Then
    MsgBox ("You cannot delete an entry that has already been sent to Accounts Department."), vbOKOnly
    Exit_DeleteEntry_Click

Else
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_DeleteEntry_Click:
    Exit Sub

Err_DeleteEntry_Click:
    MsgBox Err.Description
    Resume Exit_DeleteEntry_Click

End Sub


The code should check whether a yes/no check box is checked. If it is, it displays an error message and quits the module.

If it is not checked, it should delete the record.

Sorry in advance for any school-boy errors in this!

Yours,
Alton.
RuralGuy
It looks like you are missing an End If right above the Exit label. This should give you a compile error.
alton
Oooops! That's the one! The correct (well, working!) code is:

CODE
Private Sub DeleteEntry_Click()
On Error GoTo Err_DeleteEntry_Click
If Me![SentToAccounts] = True Then
    MsgBox ("You cannot delete an entry that has already" & (Chr(13) & Chr(10)) & "been sent to Accounts Department."), vbOKOnly
Else
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
Exit_DeleteEntry_Click:
    Exit Sub
Err_DeleteEntry_Click:
    MsgBox Err.Description
    Resume Exit_DeleteEntry_Click
End Sub


Yours,
Alton.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.