OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
I want to either trap user hits esc key or if not that, disable it. I've tried what I can find with google. Sub 1 loops and calls Sub 2 within the loop.
I tried putting Application.EnableCancelKey = xLDisabled into both subs just to disable the esc key which did not work. When user hits esc I get an overload (error # 6) and the dialog with the debug button takes me to my error handler function call (to function ErrorMessage shown below). I don't want user to see that.
I tried trapping for error # 18 in error handler but I still get an overload (error # 6) message and debug button takes me to the error handler function call (to function ErrorMessage shown below).
Here is my attempt at tapping error # 18:
Here is the error handler function which normally works.
What simple code am I missing?
I tried putting Application.EnableCancelKey = xLDisabled into both subs just to disable the esc key which did not work. When user hits esc I get an overload (error # 6) and the dialog with the debug button takes me to my error handler function call (to function ErrorMessage shown below). I don't want user to see that.
I tried trapping for error # 18 in error handler but I still get an overload (error # 6) message and debug button takes me to the error handler function call (to function ErrorMessage shown below).
Here is my attempt at tapping error # 18:
VBA Code:
ErrHandler:
CentersProgressDialog.Hide
DoEvents
If Err.Number = 18 _
Then
Exit Sub
Else
Call ErrorMessage(Err.Number, Err.Description, sSubName, sStepID)
End If
End Sub
Here is the error handler function which normally works.
VBA Code:
'Use to render the error messages from error handler.
Function ErrorMessage( _
pErrNum As Integer, _
psErrDescr, _
Optional psSubName = "", _
Optional psStepID = "")
' If pErrNum = 18 Then Exit Function
Dim sMsg As String
Dim sTitle As String
sTitle = "Error Message"
sMsg = "Error #" & pErrNum & " occurred"
If psSubName <> "" _
Then sMsg = sMsg & Chr(10) & "in procedure " & psSubName
sMsg = sMsg & "."
If psStepID <> "" _
Then sMsg = sMsg & Chr(10) & "Step ID: " & psStepID & "."
sMsg = sMsg & Chr(10) & "Error Type: " & psErrDescr & "."
MsgBox sMsg, vbOKOnly + vbCritical, sTitle
Err.Clear
Application.StatusBar = False
DoEvents
End Function
What simple code am I missing?