?
Solved

error runtime messages when open file

Posted on 2000-05-02
4
Medium Priority
?
151 Views
Last Modified: 2010-05-02
When I try to open a file which is not currently closed by another program (ex : a log of a backup exec program), I have a runtime error.

I would like to capture the error message with my open command.

Ex :
 Open ch_origine + nom For Input As #1
 
'Here I want to know if an error has been met, not to do the rest of code.
       
 Do Until EOF(1) Or dejafait
...

Thank you for your answer, and sorry for my trivial questions.

Apydya    
0
Comment
Question by:apydya
[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
  • 3
4 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2769663
Private Sub Command1_Click()
On Error GoTo trap
Open ch_origine + nom For Input As #1
On Error GoTo 0   'turn off error trap

Rem your code

Close #1

Exit Sub

trap:

    MsgBox "Error on open"

End Sub

OR DO THIS

Private Sub Command1_Click()
On Error Resume Next
Error.Clear
Open ch_origine + nom For Input As #1
If Error.num <> 0 Then

    MsgBox "Error on open"

Else

    On Error GoTo 0   'turn off error trap

    Rem your code

    Close #1

End If

End Sub
0
 
LVL 18

Expert Comment

by:deighton
ID: 2769693
deighton changed the proposed answer to a comment
0
 
LVL 18

Accepted Solution

by:
deighton earned 160 total points
ID: 2769698
Private Sub Command1_Click()
On Error Resume Next
Err.Clear
Open ch_origine + nom For Input As #1

If Err.Number <> 0 Then

    MsgBox "Error on open " & Err.Description

Else

    On Error GoTo 0   'turn off error trap

    Rem your code

    Close #1

End If

End Sub
0
 

Author Comment

by:apydya
ID: 2791399
You answer + comment is perfect.
Thank you for the time you spent.
Have a nice day.
Patrick
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 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