Good Programming Practices????

T

Turner

Below I have showing some code with a "docmd.SetWarnings
True" after the Exit_SubRoutine but before the actual
Exit Sub. The question is: Is this in Violation of Good
Programming Practices?

The Plus side of doing it this way is the Set Warnings is
always returned to a TRUE status no matter what happens.

Private Sub cmdDeleteProperty_Click()
On Error GoTo Err_cmdDeleteProperty_Click

Const stMsg As String = _
"Are You Sure You Want to Delete this Property
and All its Corresponding Leases, Loans, etc."

If MsgBox(stMsg, vbYesNo + vbCritical +
vbDefaultButton2) = vbYes Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, ,
acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, ,
acMenuVer70
Forms!frmMain.SetFocus
Else
MsgBox "No Action Taken"
End If

Exit_cmdDeleteProperty_Click:
DoCmd.SetWarnings True 'Note Location
Exit Sub

Err_cmdDeleteProperty_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteProperty_Click

End Sub
 
A

Allen Browne

Yes. It is good practice to reset things and dereference your objects in the
error recovery part of a procedure, so they are guaranted to be reset.

If you have many things in this spot, you may want to prefix them with:
On Error Resume Next
since there is no error handling at this place.
 

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