determine whether a pdf file is being viewed using vba

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

I've built an mdb that prints pdf files and occasionally users need to
reprint a pdf due to a change in data. If the pdf is being viewed it chokes
the db as it tries to give the pdf the same file name.

My question is, is there a way to determine, programatically, if the pdf file
is actually open and being viewed?
 
P

pubdude2003 via AccessMonster.com

ulp, I guess I should mention that the user would be viewing it using Acrobat
rather than an internet browser
 
P

pubdude2003 via AccessMonster.com

sigh, it seems posting to this marvelous site is all I often need to think of
a problem differently.

Here's the solution found at Microsoft under "Macro code to check whether a
file is already open"

If IsFileOpen(prmPdfName) Then
MsgBox "Please close" & prmPdfName, vbCritical, " This PDF file is open"
Exit Sub
End If

Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer

On Error Resume Next ' Turn error checking off.
filenum = FreeFile() ' Get a free file number.
' Attempt to open the file and lock it.
Open filename For Input Lock Read As #filenum
Close filenum ' Close the file.
errnum = Err ' Save the error number that occurred.
On Error GoTo 0 ' Turn error checking back on.

' Check to see which error occurred.
Select Case errnum

' No error occurred.
' File is NOT already open by another user.
Case 0
IsFileOpen = False

' Error number for "Permission Denied."
' File is already opened by another user.
Case 70
IsFileOpen = True

' Another error occurred.
Case Else
Error errnum
End Select

End Function
 
P

pubdude2003 via AccessMonster.com

Happy to!

It is a bit annoying when someone posts and then replies, "oh never mind, I
solved it"

Kind of defeats what this is all about doesn't it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top