472,983 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Opening a pdf in VBA, getting error 438

489 256MB
I've had code in my application for quite some time and now I'm getting error 438. This is the code
Expand|Select|Wrap|Line Numbers
  1. Print fHandleFile(app_path + "\shb.pdf", WIN_NORMAL)
this calls the FHandleFile function
Expand|Select|Wrap|Line Numbers
  1. Function fHandleFile(stFile As String, lShowHow As Long)
  2. Dim lRet As Long, varTaskID As Variant
  3. Dim stRet As String
  4. Dim Vresponse As String
  5.    'First try ShellExecute
  6.     lRet = apiShellExecute(hWndAccessApp, vbNullString, _
  7.             stFile, vbNullString, vbNullString, lShowHow)
  8.  
  9.     If lRet > ERROR_SUCCESS Then
  10.         stRet = vbNullString
  11.         lRet = -1
  12.     Else
  13.         Select Case lRet
  14.             Case ERROR_SUCCESS:
  15.                 varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
  16.                         & stFile, WIN_NORMAL)
  17.                 lRet = (varTaskID <> 0)
  18.             Case ERROR_NO_ASSOC:
  19.                 'Try the OpenWith dialog
  20.                 varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
  21.                         & stFile, WIN_NORMAL)
  22.                 lRet = (varTaskID <> 0)
  23.             Case ERROR_OUT_OF_MEM:
  24.                 stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
  25.             Case ERROR_FILE_NOT_FOUND:
  26.                 stRet = "Error: Adobe acrobat reader not installed.  Couldn't Execute!"
  27.             Case ERROR_PATH_NOT_FOUND:
  28.                 stRet = "Error: Path not found. Couldn't Execute!"
  29.             Case ERROR_BAD_FORMAT:
  30.                 stRet = "Error:  Bad File Format. Couldn't Execute!"
  31.             Case Else:
  32.         End Select
  33.     End If
  34.     fHandleFile = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
  35.     If fHandleFile = -1 Then
  36.  
  37.     Else
  38.         Vresponse = MsgBox(fHandleFile, vbOKOnly, "" & VMsgtitle & "")
  39.     End If
  40. End Function
  41.  
When it comes to the LRet code line is when I'm getting the 438 error "Object Doesn't support this property of method" however it does open the pdf.
I've tried using the Application.followhyperlink method but that give me a security error, that comes from Microsoft office "Opening shb.pdf Some files can contain viruses or otherwise e harmful to your computer. It is important to be certain that this file is from a trustworthy source. Would you like to open this file?"
I know this file if safe and is part of my application so I don't want that to show.
Either method is fine with me if I can figure out a way to do away with the error 438 or eliminate the security warming.
Any help is always appreciated.
Thanks
Oct 29 '17 #1

✓ answered by twinnyfo

Try replacing Print with Open

5 2921
twinnyfo
3,653 Expert Mod 2GB
CD Tom,

I am not sure if you "need" to have such extensive code to print a PDF.

I use the following Code:

Expand|Select|Wrap|Line Numbers
  1.     strPrint = app_path + "\shb.pdf"
  2.     ShellExecute 0, "Print", strPrint, "", "", 0
Then, in a separate Module, declare the Function:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function ShellExecute _
  2.     Lib "shell32.dll" _
  3.     Alias "ShellExecuteA" ( _
  4.     ByVal hwnd As Long, _
  5.     ByVal lpOperation As String, _
  6.     ByVal lpFile As String, _
  7.     ByVal lpParameters As String, _
  8.     ByVal lpDirectory As String, _
  9.     ByVal nShowCmd As Long) _
  10.     As Long
It should work printing any file to your default printer. Unless I am missing something obvious, this should serve your purposes. Please clarify if it does not.

Hope this hepps!
Jan 2 '18 #2
CD Tom
489 256MB
Thanks for the reply. Now when I try your code I get "There was an error opening this document. The file is damaged and could not be repaired" If I just go to the document in explorer and double click it open just fine. Also I just want to display the document on the screen not print it.
What do you suggest.
Jan 4 '18 #3
twinnyfo
3,653 Expert Mod 2GB
Try replacing Print with Open
Jan 5 '18 #4
CD Tom
489 256MB
Worked perfect thanks so much
Jan 5 '18 #5
twinnyfo
3,653 Expert Mod 2GB
So glad I could be of some hepp!

Cheers!
Jan 5 '18 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
0
by: Hemangi | last post by:
hi friends, I have one problem with VSTO 2005. As I try to open new project using word document in VSTO 2005, I am getting error Specified cast is not valid...and the project is not opening.Please...
5
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
12
by: tvnaidu | last post by:
Trying to mount windows folder on Linux machine, getting this error. I have a folder called "CheckIn" on windows, I made that folder as Network sharing. ON lInux, I tried to access that folder by...
2
by: bandy | last post by:
Hi there sorry If I posted this thread under wrong head. When I am trying to run my site I am getting error as Internal Server Error, but when I refresh page , i get result properly. I don't...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.