Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intercept Error Msg

Status
Not open for further replies.

Fattire

Technical User
Nov 30, 2006
127
0
0
US
I have a form that enables the user to select an excel file they can import into the database. Problem is that some of these excel files get saved on accident after someone has changed the columns.

The user gets "Run-time error '3274': External table is not the expected format."

Is there a way I can intercept this message and give them my own message?
 
Got it:

Code:
Exit_Sub:
    Exit Sub
    
ErrorTest_1:
MsgBox "This excel file has been changed to by someone; the columns don't match the table it goes into." & vbCrLf & vbCrLf & "Error Number " & Err.Number & vbCrLf & Err.Description, vbCritical, "Bad Excel"
Resume Exit_Sub
 
Or, for completeness...

Code:
Test Sub()

On Error Goto ErrorTest_1

'Your code here

Exit Sub

ErrorTest_1:

Select Case Err.Number
   Case 3274
     MsgBox "This excel file has been changed to by someone; the columns don't match the table it goes into." & vbCrLf & vbCrLf & "Error Number " & Err.Number & vbCrLf & Err.Description, vbCritical, "Bad Excel"
   Case Else
     MsgBox "An Error has ocurred, please report the following to wherever..." & vbCrLf & vbCrLf & "Error Number " & Err.Number & vbCrLf & vbCrLf & "Error Description " & Err.Description, vbCCritical, "Error"
End Select

End Sub

This will catch all errors and notify the user...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top