Article ID: 167855
Article Last Modified on 1/19/2007
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()
Select Case Application.SysCmd(acSysCmdAccessVer)
Case "7.0"
varOldBOAEOptions = GetOption("Break On All Errors")
SetOption "Break On All Errors", False
Case "8.0"
varOldBOAEOptions = GetOption("Error Trapping")
SetOption "Error Trapping", 2
End Select
End Sub
'-----------------------------------------------------------------
' Restore the "Break on All Errors" settings that were temporarily
' suspended by the SuspendBreaks procedure.
'-----------------------------------------------------------------
Public Sub ResumeBreaks()
Select Case Application.SysCmd(acSysCmdAccessVer)
Case "7.0"
If Not IsEmpty(varOldBOAEOptions) Then _
SetOption "Break On All Errors", varOldBOAEOptions
Case "8.0"
If Not IsEmpty(varOldBOAEOptions) Then _
SetOption "Error Trapping", varOldBOAEOptions
End Select
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 Workspace
Set ws = 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
Additional query words: BreakOnAllErrors BreakInClassModule BreakOnUnhandledErrors
Keywords: kbcode kbhowto kbprogramming KB167855