UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Shell Command Line Open Pdf, Access 2010    
 
   
jukos
post Oct 11 2018, 03:31 PM
Post#1



Posts: 27
Joined: 31-May 16



I am trying to improve on code that is working. At the moment I am able to launch a pdf viewer called sumatra pdf and open a file. The trouble is that i have only had success when teh file name has no spaces in it. I would like it work with a file with spaces in the filename. The code is as follows.

when user clicks on command42 button there is a call to a function in a module that will open the pdf to a page with the value for "strpdfpage = Me.pmitasknumber.Value" which is a value from a form record. At the moment the file its opening is called "tb_v2.x.pdf" but I would like it to be able to use files with spaces in the filename such as "tb v2.x.pdf"

Private Sub Command42_Click()

If Not IsNull(Me.pmitasknumber.Value) Then
strpdfpage = Me.pmitasknumber.Value


strpdfexepath = "\\GRH503\Electronics\database_programs\truebeam_PMI\supporting_files\pmi_pdf\SumatraPDF.exe"


strpdfdocpath = " \\GRH503\Electronics\database_programs\truebeam_PMI\supporting_files\pmi_pdf\tb_v2.x.pdf"

Call openpdf(strpdfpage, strpdfexepath, strpdfdocpath)

End If

End Sub


the function that is called is ..

Public Function openpdf(ByVal strpdfpage As String, ByVal strpdfexepath As String, ByVal strpdfdocpath As String)

Dim strpdffinalpath, strpdfparam As String

strpdfparam = "-named-dest"

strpdffinalpath = strpdfexepath & " " & strpdfparam & " " & strpdfpage & " " & strpdfdocpath

Shell strpdffinalpath

End Function


Thank you for any ideas, help.

John


Go to the top of the page
 
DanielPineault
post Oct 11 2018, 07:42 PM
Post#2


UtterAccess VIP
Posts: 6,135
Joined: 30-June 11



Try surrounding the output of strpdfdocpath with double quote.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
Doug Steele
post Oct 11 2018, 07:47 PM
Post#3


UtterAccess VIP
Posts: 21,970
Joined: 8-January 07
From: St. Catharines, ON (Canada)


See whether this works:

CODE
strpdffinalpath = strpdfexepath & " " & strpdfparam & " " & strpdfpage & " """ & strpdfdocpath & """"

Another option would be to use the fGetShortName code in Get Short and Long file names at "The Access Web" to ensure you don't have any spaces in the path being passed.



--------------------
Doug Steele, Microsoft Access MVP (2000-2018)
http://www.accessmvp.com/DJSteele/AccessIndex.html
Co-author: Access Solutions: Tips, Tricks, and Secrets from Microsoft Access MVPs, published by Wiley
Co-author: Effective SQL: 61 Specific Ways to Write Better SQL, published by Addison-Wesley Professional
Technical Editor: Access 2010 Bible, Access 2013 Bible, Access 2016 Bible, all published by Wiley
Technical Editor: SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, 4th Edition, published by Addison-Wesley Professional
Go to the top of the page
 
jukos
post Oct 12 2018, 12:36 PM
Post#4



Posts: 27
Joined: 31-May 16



Thanks guys...

Daniel, I get a compile error, expected end statement when i surround with double quotes.

Doug, the code didnt work out. Not sure how to get the fGetShortName code to return string, could you help with that?

Thanks!
Go to the top of the page
 
Doug Steele
post Oct 12 2018, 02:42 PM
Post#5


UtterAccess VIP
Posts: 21,970
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Before bothering with the fGetShortName approach, did the first alternative I suggested not work? (It's essentially the double-quote approach Daniel suggested).

If you want to use fGetShortName, copy everything in the shaded area between Code Start and Code End into a new module. Make sure you choose a unique name for the module (i.e.: it cannot be named the same as any of the functions or subs within it). Once that's done, try

CODE
  strpdffinalpath = strpdfexepath & " " & strpdfparam & " " & strpdfpage & " " & fGetShortName(strpdfdocpath)

--------------------
Doug Steele, Microsoft Access MVP (2000-2018)
http://www.accessmvp.com/DJSteele/AccessIndex.html
Co-author: Access Solutions: Tips, Tricks, and Secrets from Microsoft Access MVPs, published by Wiley
Co-author: Effective SQL: 61 Specific Ways to Write Better SQL, published by Addison-Wesley Professional
Technical Editor: Access 2010 Bible, Access 2013 Bible, Access 2016 Bible, all published by Wiley
Technical Editor: SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, 4th Edition, published by Addison-Wesley Professional
Go to the top of the page
 
DanielPineault
post Oct 12 2018, 04:21 PM
Post#6


UtterAccess VIP
Posts: 6,135
Joined: 30-June 11



Try

strpdfdocpath = chr(34) & "\\GRH503\Electronics\database_programs\truebeam_PMI\supporting_files\pmi_pdf\tb_v2.x.pdf" & chr(34)

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
projecttoday
post Oct 12 2018, 04:30 PM
Post#7


UtterAccess VIP
Posts: 10,186
Joined: 10-February 04
From: South Charleston, WV


Are you saying that you have successfully opened "tb_v2.x.pdf" but cannot open "tb v2.x.pdf" as part of a file path (and there is a file by that name)?

If so then I think you have a Windows issue, not an Access issue (which doesn't solve your problem, of course). If not, ignore the following: I'm pretty sure it can be done. I just don't remember how exactly. I think it involves ~. What's the command for displaying files in dos prompt, dir? How do you display that file dos prompt?

--------------------
Robert Crouser
Go to the top of the page
 
jukos
post Oct 16 2018, 02:48 PM
Post#8



Posts: 27
Joined: 31-May 16



@Doug, the first soln you provided with the double quotes opens the pdf as shown in the attachment.Attached File  dbl_quote_soln.gif ( 10.87K )Number of downloads: 3
Go to the top of the page
 
jukos
post Oct 16 2018, 02:52 PM
Post#9



Posts: 27
Joined: 31-May 16



@Doug the fgetshortname code you provided produces an empty home page of sumatra pdf as shown in attachment.Attached File  fgetshortname.gif ( 9.15K )Number of downloads: 2
Go to the top of the page
 
jukos
post Oct 16 2018, 03:20 PM
Post#10



Posts: 27
Joined: 31-May 16



@Daniel the result of using Chr (34) is as shown in attachment.Attached File  chr_34.gif ( 8.1K )Number of downloads: 3
Go to the top of the page
 
jukos
post Oct 16 2018, 03:24 PM
Post#11



Posts: 27
Joined: 31-May 16



@projecttoday yep the file without spaces in filename is fine as shown in attachment.Attached File  nospace.gif ( 27.16K )Number of downloads: 3
Go to the top of the page
 
Doug Steele
post Oct 16 2018, 07:09 PM
Post#12


UtterAccess VIP
Posts: 21,970
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Does fGetShortName return something when passed a path?

--------------------
Doug Steele, Microsoft Access MVP (2000-2018)
http://www.accessmvp.com/DJSteele/AccessIndex.html
Co-author: Access Solutions: Tips, Tricks, and Secrets from Microsoft Access MVPs, published by Wiley
Co-author: Effective SQL: 61 Specific Ways to Write Better SQL, published by Addison-Wesley Professional
Technical Editor: Access 2010 Bible, Access 2013 Bible, Access 2016 Bible, all published by Wiley
Technical Editor: SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, 4th Edition, published by Addison-Wesley Professional
Go to the top of the page
 
DanielPineault
post Oct 16 2018, 08:29 PM
Post#13


UtterAccess VIP
Posts: 6,135
Joined: 30-June 11



What about

CODE
Public Sub Command42_Click()
      Dim strpdfpage            As String    '????
      Dim strpdfexepath         As String
      Dim strpdfdocpath         As String
      Const sSumatraPath = "\\GRH503\Electronics\database_programs\truebeam_PMI\supporting_files\pmi_pdf\"
  
      If Not IsNull(Me.pmitasknumber) Then
          strpdfpage = Me.pmitasknumber
          strpdfexepath = sSumatraPath & "SumatraPDF.exe"
          strpdfdocpath = sSumatraPath & "tb_v2.x.pdf"
          Call openpdf(strpdfpage, strpdfexepath, strpdfdocpath)
      End If
  End Sub
  
  Public Function openpdf(ByVal strpdfpage As String, ByVal strpdfexepath As String, ByVal strpdfdocpath As String)
      Dim strpdffinalpath       As String
      Dim strpdfparam           As String
  
      strpdfparam = "-named-dest"
      strpdffinalpath = """" & strpdfexepath & """ " & strpdfparam & " " & strpdfpage & " """ & strpdfdocpath & """"
      Shell strpdffinalpath
  End Function


Be sure to add error handling.

Be careful as your original code included extra spaces, that can in certain cases cause problems.




You can also find some sample code at https://forum.openoffice.org/fr/forum/viewt...+avec+programme (search for SumatraPDF.exe)


--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
jukos
post Oct 17 2018, 08:43 AM
Post#14



Posts: 27
Joined: 31-May 16



Daniel, the code you shared is working. Your code didn't have a space in the filename but I tried it with a filename that did have a space and its good!


Doug, the fgetshortname doesnt seem to return anything,see attachedAttached File  fgetshortname_return.gif ( 22.88K )Number of downloads: 6
Go to the top of the page
 
jukos
post Oct 17 2018, 12:53 PM
Post#15



Posts: 27
Joined: 31-May 16



Thank you all for your help, very kind of you!
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd October 2018 - 11:49 PM