Consulting

Results 1 to 2 of 2

Thread: "locked for editing" check

  1. #1

    "locked for editing" check

    Hi all,

    I have an access database, which opens word's and ppt's and populates certain fields in it. If several users use the database and generate at the very same moment the .doc's and the ppt's, they get a "locked-for-editing" pop-up.

    What I would like to do in order to solve this, is create a loop in the VBA code which checks whether the doc is locked for editing. If it is not locked, the vba code continues, if it is locked, the check repeats itself.

    Unfortunately, I don't know the codeline how to check whether a document is locked or not.

    Can anybody help?

    Thanks a lot!


  2. #2
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    Sub TestFile()
    If IsFileLocked( sFile) Then
       MsgBox "LOCKED"
    Else
       MsgBox "available"
    End If
    End Sub
    
    Public Function IsFileLocked(psFileName As String) As Boolean
       On Error Resume Next
       ' If the file is already opened by another process,
       ' and the specified type of access is not allowed,
       ' the Open operation fails and an error occurs.
       Open psFileName For Binary Access Read Write Lock Read Write As #1
       Close #1
       ' If an error occurs, the document is currently open.
       If Err.Number <> 0 Then
          ' Display the error number and description.
          'MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
          IsFileLocked = True
          Err.Clear
       End If
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •