473,394 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 2962
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.