?
Solved

Error Trapping Help !

Posted on 2003-03-21
1
Medium Priority
?
135 Views
Last Modified: 2010-05-01
let's say i want to read a file content from a:\test1.txt . If the floppy disk is not inserted ,or it cannot read the file or whatever run-time error , how can i display a msgbox "error!" rather than those Run-time error msg ?
0
Comment
Question by:ANGWK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 60 total points
ID: 8180069
Hi ANGWK,

On Error Goto errHandler

'Here is your code for reading the file:

Exit Sub

errHandler:
  Select Case err.Number
  Case 52
    Msgbox "File Not Found"
  Case 75
    Msgbox "Access Denied"
  Case Else
    Msgbox "Some other error occured"
  End Select
  Resume Next 'Allows you to resume processing at the next statement
Exit Sub

This is basic error handling process and should be implemented in every function/sub that requires it.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question