Solved

error runtime messages when open file

Posted on 2000-05-02
4
138 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 40 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now