This article was previously published under Q209884
Advanced: Requires expert coding, interoperability, and multiuser skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Dim varOldBOAEOptions As Variant
'-----------------------------------------------------------------
' Save the current setting for the "Break on All Errors" option
' Turn off the "Break on All Errors" option.
'-----------------------------------------------------------------
Public Sub SuspendBreaks()
varOldBOAEOptions = GetOption("Error Trapping")
SetOption "Error Trapping", 2
End Sub
'-----------------------------------------------------------------
' Restore the "Break on All Errors" settings that were temporarily
' suspended by the SuspendBreaks procedure.
'-----------------------------------------------------------------
Public Sub ResumeBreaks()
If Not IsEmpty(varOldBOAEOptions) Then _
SetOption "Error Trapping", varOldBOAEOptions
End Sub
Function MyCodeModule()
SuspendBreaks
On Error GoTo MyCodeModule_Err
' Add your code here.
MyCodeModule_Exit:
ResumeBreaks
Exit Function
MyCodeModule_Err:
' Add your error handling routine here.
Resume MyCodeModule_Exit
End Function
Form: frmTestErrors ---------------------------------------------------- Caption: Test Error Handling Text box: Name: txtUName Text box: Name: txtPwd Command button: Name: cmdOK Caption: Without Turning Off Break On All Errors OnClick: [Event Procedure] Command button: Name: cmdOKBreakOff Caption: Turning Off Break On All Errors OnClick: [Event Procedure] Command button: Name: cmdCancel Caption: Cancel OnClick: [Event Procedure]
'---------------------------------------------------------------
' Test UserName and Password.
' Returns:
' True if UserName and Password are valid.
' False if UserName and Password are invalid.
' Displays corresponding error message.
'-------------------------------------------------------------
Public Function ChkPwd(uid As String, strPwd As String)
On Error GoTo badPwd
Dim ws As DAO.Workspace
Set ws = DAO.DBEngine.CreateWorkspace("TestPWD", uid, strPwd)
MsgBox "Your password is correct, " & uid
ChkPwd = True
exitChkPwd:
Exit Function
badPwd:
MsgBox "Not the right UserName or Password, " & uid & _
", if that is your real name!"
ChkPwd = False
Resume exitChkPwd
End Function
Private Sub cmdOK_Click() ' Without "Break on All Errors" turned off.
Call ChkPwd(Me![txtUName] & "", Me![txtPwd] & "")
End Sub
Private Sub cmdOKBreakOff_Click()
SuspendBreaks ' Turn off "Break on All Errors."
Call ChkPwd(Me![txtUName] & "", Me![txtPwd] & "")
ResumeBreaks ' Reset "Break on All Errors."
End Sub
Private Sub cmdCancel_Click()
DoCmd.Close
End Sub
Keywords: KB209884, kbprogramming, kbhowto, kbcode