Hi
I was reading about Using Err.Raise and I had a question or few that I was holing someone could answer. Here is the article I am referencing: Link
If I were to add Err.Raise to the code, when an error occurs in the section of code, it should go to Pub Cost ERROR_INVALID_DATA. If there is an ON ERROR GOTO eh, that should override the Err.Raise?
Which takes priority over the other? What are the conditions that this occurs? If Err.Raise is before ON ERROR GOTO eh, does Err.Raise default or will ON ERROR GOTO eh override the Err.Raise?
Thanks,
Mike
I was reading about Using Err.Raise and I had a question or few that I was holing someone could answer. Here is the article I am referencing: Link
If I were to add Err.Raise to the code, when an error occurs in the section of code, it should go to Pub Cost ERROR_INVALID_DATA. If there is an ON ERROR GOTO eh, that should override the Err.Raise?
Which takes priority over the other? What are the conditions that this occurs? If Err.Raise is before ON ERROR GOTO eh, does Err.Raise default or will ON ERROR GOTO eh override the Err.Raise?
Code:
If Len(Sheet1.Range("A1")) <> 5 Then
Err.Raise ERROR_INVALID_DATA, "ReadWorksheet" _
, "The value in the cell A1 must have exactly 5 characters."
End If
Code:
Public Const ERROR_INVALID_DATA As Long = vbObjectError + 513
Sub ReadWorksheet()
On Error Goto eh
If Len(Sheet1.Range("A1")) <> 5 Then
Err.Raise ERROR_INVALID_DATA, "ReadWorksheet" _
, "The value in the cell A1 must have exactly 5 characters."
End If
' continue on if cell has valid data
Dim id As String
id = Sheet1.Range("A1")
Done:
Exit Sub
eh:
' Err.Raise will send code to here
MsgBox "Error found: " & Err.Description
End Sub
Thanks,
Mike