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
shieldscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
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.
shieldscoAuthor Commented:
After making the suggested change a new error message...the file cannot be found
Shaun KlineLead Software EngineerCommented:
The DIR function returns the file name with the extension. In your Shell call, you are appending the extension, which should not be needed.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

shieldscoAuthor Commented:
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)
Shaun KlineLead Software EngineerCommented:
Should this:
 & folder & file & 

Open in new window

be:
 & folder & "\" & file &

Open in new window

?
shieldscoAuthor Commented:
After making change I get the same result....file cannot be found
Shaun KlineLead Software EngineerCommented:
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)
shieldscoAuthor Commented:
No... Acrobat Reader launches and  throws the error message
Shaun KlineLead Software EngineerCommented:
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.
shieldscoAuthor Commented:
No to both
Shaun KlineLead Software EngineerCommented:
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.
Gustav BrockCIOCommented:
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
shieldscoAuthor Commented:
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
shieldscoAuthor Commented:
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)
Shaun KlineLead Software EngineerCommented:
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.
Gustav BrockCIOCommented:
> There was an error opening this document.. file could not be found

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

/gustav
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
As I suggested in the other thread and as gustav has here as well, always build up your command and SQL Statements in a string variable first.

This allows you to:

1. See specific errors when the string is built - they don't get hidden by some command not working or giving strange errors.

2. STOP on the execute line and inspect the string contents before the command using it executes it.

  While it is a bit more overhead for the program, the slight difference is far out weighed when it comes to trouble shooting both now and possibly in the future.

Jim.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.