Link to home
Start Free TrialLog in
Avatar of shieldsco
shieldscoFlag for United States of America

asked on

Access VBA Error Opening Adobe

Adobe Opens with this error message : there was an error opening this document ... the specified path is invalid. I'm using the code below to prompt the user to select the folder where the files are located and then print continuously.

Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim vrtSelectedItem As Variant

TryAgain:
With fd
    .InitialView = msoFileDialogViewDetails ' msoFileDialogViewThumbnail
    .Title = "Folder Selector"
    '.InitialFileName = theFile
    .ButtonName = "Use this folder"
    .AllowMultiSelect = False

    'The user pressed the action button.
    If .Show = True Then
        If .SelectedItems.Count = 0 Then
            MsgBox "You didn't make a valid selection.  Try again!"
            GoTo TryAgain
        End If
        MsgBox .SelectedItems(1)


Dim file As String
 Dim folder As String
  folder = fd.SelectedItems(1)
 file = Dir(folder & "\*.pdf")
 Do Until Len(file) = 0
   
 
Call Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe /N /T /" & folder & "\" & file & ".pdf /WOC4FL-4177", vbNormalFocus)
   file = Dir

Loop


        Exit Sub
    End If
End With
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

If your intent is to open a new session of Acrobat Reader and send the document directly to the printer, it appears that your parameters are not correct. According to the developer FAQ on Adobe's website (http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/intro_to_sdk/DeveloperFAQ.pdf, page 27), the parameters should be /N /T <path> <printer name> <driver name> <port>. The slash you have prior to both the document path and printer do not appear to be needed. It does not state if the last two are optional, but try without them to see if you get different results.
Avatar of shieldsco

ASKER

After making the suggested change a new error message...the file cannot be found
The DIR function returns the file name with the extension. In your Shell call, you are appending the extension, which should not be needed.
I get the same error ... file cannot be found

Call Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe /N /T " & folder & file & " WOC4FL-4177", vbNormalFocus)
Should this:
 & folder & file & 

Open in new window

be:
 & folder & "\" & file &

Open in new window

?
After making change I get the same result....file cannot be found
Is Acrobat Reader launching and throwing the error message, or is your Access application throwing the error? If it is the latter, you may need to enclose the application name in quotation marks like this:
Call Shell("""C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe"" /N /T " & folder & file & " WOC4FL-4177", vbNormalFocus)
No... Acrobat Reader launches and  throws the error message
Does the path to the file you are attempting to open have spaces in the path or file name? If so, you'll need to enclose that in double quotation marks.
No to both
If you debug your code, placing a break point at the Call Shell line, use the Immediate window to evaluate call. I.e. enter this in the Immediate Window:
? """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe"" /N /T " & folder & "\" & file & " WOC4FL-4177"

Open in new window


After that evaluates, copy the result to the Windows Run command (or to a command prompt) to see if it launches Acrobat Reader correctly and prints the document.
I don't understand why you don't get the command line straight before putting it into Shell.

Still, given the syntax from Adobe, try if your printer is WOC4FL-4177:
Call Shell(Chr(34) & "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe" & Chr(34) & " /N /T " & Chr(34) & "folder & "\" & file & ".pdf" & Chr(34) & " WOC4FL-4177", vbNormalFocus)

Open in new window

/gustav
Shaun - I did as you suggested... Adobe opened and Adobe produce the following error:
There was an error opening this document.. file could not be found
Gustav - syntax error

Call Shell(Chr(34) & "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\acrord32.exe" & Chr(34) & " /N /T " & Chr(34) & "folder & "\" & file & ".pdf" & Chr(34) & " WOC4FL-4177", vbNormalFocus)
It would seem, then, that the generated location of the file in question does not match the physical location. Compare what was generated for the file location to the actual location to determine how you need to change your code to get the correct location.
> There was an error opening this document.. file could not be found

Then please adjust until success and post the final string here.

/gustav
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial