Solved

Is File Open From Vb5 APP

Posted on 1998-07-13
5
172 Views
Last Modified: 2010-05-03
How do i know if for example Excel file is open from Vb5 Application, befor i am trying to delete  this file so i will not get an error while trying to delete an open file.
Is there any function in vb5 or dll function in winodws api?
0
Comment
Question by:gali040898
[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
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:chris_a
ID: 1465671
Switch off error trapping, try to delete it, then see if it still there (you could event check the last error code)!
0
 

Author Comment

by:gali040898
ID: 1465672
i have to delete the file!!!
0
 
LVL 9

Accepted Solution

by:
Dalin earned 20 total points
ID: 1465673
gali,
Try this, see if it works for you.
Regards
Dalin

Function KillFile
 
Dim lifh As Integer ' file handle variable

On Error GoTo fFileExistErrorHandler '    enable our error handler
   
   lifh = FreeFile ' get the next available free file handle
   Open TheFile For Input As lifh ' try and open it for reading
   Close lifh ' be sure to close it
   Kill theFile
   Exit Function

fFileExistErrorHandler:
   Select Case Err
          Case 52  'bad file name or number
         
            Exit Function
          Case 53  'file not found
         
            Exit Function
          Case 55  'file already open
            'File is Open Somewhere
           
            Exit Function

         
          Case 75  'path/file access error
           
            Exit Function
          Case 76  'path not found
           
            Exit Function
          Case Else ' something else happened - so just report it
           
            Exit Function
   End Select

End Function
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1465674
Gali,
You should pass the fileName with full path.

Function KillFile (theFile as String) as Boolean
.
0
 

Author Comment

by:gali040898
ID: 1465675
Dalin Thanks!
I just Used The kill File_name with the error handler.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

730 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