Solved

error runtime messages when open file

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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 Month10 days, 11 hours left to enroll

632 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