Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

error runtime messages when open file

Posted on 2000-05-02
4
Medium Priority
?
153 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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

876 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