The other method of executing code based on certain conditions is by using a Select Case. In this, the error code is passed through a series of Case statements until the value matches that of the Err.Number value. The following code example deals with the same situation as that in the IF…THEN…ELSE block of code above, but as a Select Case.

Private Sub cmdSaveAs_Click()
On Error Resume Next

CommonDialog1.ShowSave

Select Case Err.Number
Case 0:
'Do Nothing
Case 58:
MsgBox "File Already Exists"
Case Else:
MsgBox "Fatal Error: " & Err.Description
End Select
Err.Clear
CommonDialog1.ShowOpen
End Sub