Started getting Object doesn't support this property or method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CD Tom
    Contributor
    • Feb 2009
    • 495

    #1

    Started getting Object doesn't support this property or method

    I keep getting this message when I try and print a PDF from within my program. This is a one line of code that calls the fhandleFile that I picked up from Dev Ashish. It was working when I tested it but that was quite some time ago. I was doing some changes and happened to click on the button to run this the PDF shows up just fine but then I get that error. This is the code to run the print
    Code:
    Print fHandleFile(App_path + "\manual.pdf", WIN_NORMAL)
    The fHandlefile code is
    Code:
    '************ Code Start **********
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    Private Declare Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hWnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
    
    '***App Window Constants***
    Private Const WIN_NORMAL = 1         'Open Normal
    Private Const WIN_MAX = 3            'Open Maximized
    Private Const WIN_MIN = 2            'Open Minimized
    
    '***Error Codes***
    Private Const ERROR_SUCCESS = 32&
    Private Const ERROR_NO_ASSOC = 31&
    Private Const ERROR_OUT_OF_MEM = 0&
    Private Const ERROR_FILE_NOT_FOUND = 2&
    Private Const ERROR_PATH_NOT_FOUND = 3&
    Private Const ERROR_BAD_FORMAT = 11&
    '***************Usage Examples***********************
    'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
    'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
    'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
    'Handle Unknown extensions (call Open With Dialog):
    '                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
    'Start Access instance:
    '                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
    '****************************************************
    
    Function fHandleFile(stFile As String, lShowHow As Long)
    Dim lRet As Long, varTaskID As Variant
    Dim stRet As String
    Dim Vresponse As String
        'First try ShellExecute
        lRet = apiShellExecute(hWndAccessApp, vbNullString, _
                stFile, vbNullString, vbNullString, lShowHow)
                
        If lRet > ERROR_SUCCESS Then
            stRet = vbNullString
            lRet = -1
        Else
            Select Case lRet
                Case ERROR_SUCCESS:
                    varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                            & stFile, WIN_NORMAL)
                    lRet = (varTaskID <> 0)
                Case ERROR_NO_ASSOC:
                    'Try the OpenWith dialog
                    varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                            & stFile, WIN_NORMAL)
                    lRet = (varTaskID <> 0)
                Case ERROR_OUT_OF_MEM:
                    stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
                Case ERROR_FILE_NOT_FOUND:
                    stRet = "Error: Adobe acrobat reader not installed.  Couldn't Execute!"
                Case ERROR_PATH_NOT_FOUND:
                    stRet = "Error: Path not found. Couldn't Execute!"
                Case ERROR_BAD_FORMAT:
                    stRet = "Error:  Bad File Format. Couldn't Execute!"
                Case Else:
            End Select
        End If
        fHandleFile = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
        If fHandleFile = -1 Then
           
        Else
            Vresponse = MsgBox(fHandleFile, vbOKOnly, "" & VMsgtitle & "")
        End If
    End Function
    The FHandlefile runs fine and the PDF prints the error is on the Print line.

    I don't know if I'm missing a reference or what.
    Any help .
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3665

    #2
    Tom,

    Have you tried using this:

    Assuming you have some pdf reader installed, then you can print with the following command:

    Code:
    CreateObject("Shell.Application").Namespace(0).ParseName("C:\mypdf1.pdf").InvokeVerb ("Print")
    You can use the above to print just about any file that supports a right click on the file name and then choosing print.

    Comment

    • Hennepin
      New Member
      • Oct 2009
      • 25

      #3
      I have been using the same code for years but modified it slightly to print.

      Code:
      Public Function fHandleFile(stFile As String, lShowHow As Long, Optional doprint As Boolean = False)
      Dim lRet As Long, varTaskID As Variant
      Dim stRet As String, stoperation As String
          stoperation = vbNullString
          If doprint Then stoperation = "print"
          'First try ShellExecute
          lRet = apiShellExecute(hWndAccessApp, stoperation, _
                  stFile, vbNullString, vbNullString, lShowHow)
                  
          If lRet > ERROR_SUCCESS Then
              stRet = vbNullString
              lRet = -1
          Else
              Select Case lRet
                  Case ERROR_NO_ASSOC:
                      'Try the OpenWith dialog
                      varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & stFile, WIN_NORMAL)
                      lRet = (varTaskID <> 0)
                  Case ERROR_OUT_OF_MEM:
                      stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
                  Case ERROR_FILE_NOT_FOUND:
                      stRet = "Error: File not found.  Couldn't Execute!"
                  Case ERROR_PATH_NOT_FOUND:
                      stRet = "Error: Path not found. Couldn't Execute!"
                  Case ERROR_BAD_FORMAT:
                      stRet = "Error:  Bad File Format. Couldn't Execute!"
                  Case Else:
              End Select
          End If
          fHandleFile = lRet & IIf(stRet = "", vbNullString, ", " & stRet)
      End Function

      Comment

      Working...