Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

In Access vba detect whether an excel file is open

Posted on 2011-09-21
3
Medium Priority
?
310 Views
Last Modified: 2012-05-12
I want to read/update information off an excel spreadsheet but don't want to do this while someone has it open. You cannot delete a file when someone has it open so system must record somewhere? - is there a way of finding out if a file is opened by someone - this file will be on a network drive. I looked on the FileSystemObject but could not see anything obvious to tell me.
0
Comment
Question by:donhannam
[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 Comments
 
LVL 12

Expert Comment

by:danishani
ID: 36577015
Check below thread out of Ron de Bruin, scroll down, and you find a nice solution:
http://www.rondebruin.nl/exist.htm

Or this thread:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=468

Hope this helps,
Daniel
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 2000 total points
ID: 36577107
Hi Don

Try this function:
Public Function FileIsLocked(strFileName As String) As Boolean
Dim hFile As Long
  On Error Resume Next
  hFile = FreeFile
  Open strFileName For Input Lock Read Write As #hFile
  Select Case Err.Number
    Case 0
      Close #hFile
      FileIsLocked = False
    Case 70
      FileIsLocked = True
    Case Else
      MsgBox "Error opening " & strFileName & vbCrLf & Err.Description, vbExclamation
      FileIsLocked = True
  End Select
  Err.Clear
End Function

Open in new window


It simply attempts to open the file for exclusive read access and checks the failure status.

Best regards,
Graham Mandeno [Access MVP 1996-2011]
0
 

Author Closing Comment

by:donhannam
ID: 36578372
Thanks Graham works perfectly

danishani: Think the links you had effectively do the same thing but prefered the one Graham provided.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

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