Results 1 to 5 of 5
  1. #1
    Karyn is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    13

    Change PDF used in report via VBA

    I can use VBA to change the image used in a report so that I can (for example) show a different image for each record in a report. I want to be able to do this with emebedded PDFs, that is if the user asks for a report on a particular contract, the report gives a summary of the data and includes a PDF (previously stored on disk) of the signed agreement. Is this possible, or will I have to convert all PDFs to images?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Did you try putting an OLE box on the form and assign it to the field? (i never tried this)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    AFAIK, the only way to display PDFs in Access is with Browser control on a form.

    Can use an Image control with other image file types to dynamically display on form/report. Don't need VBA. Image control has ControlSource property. Images can be embedded in attachment type field or store external image path/filename in text field. Bind Image control to the field.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by ranman256 View Post
    Did you try putting an OLE box on the form and assign it to the field? (i never tried this)
    I think I have done this with a form before. Never tried it in Report View with a report, though.

  5. #5
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Opening PDF/DOCx etc fiels using VBA

    I would love to take credit for this but I can't I have used this successfully for opening Word and PDF files.
    [Code]
    Public Sub OpenSpecFile(strpath As String, Optional strPageNumber As String, Optional strZoomValue As String)

    'Opens a PDF/DOCX etc file sto a specific page and with a specific zoom
    'using Adobe Reader Or Adobe Professional.
    'API functions are used to specify the necessary windows
    'and send the page and zoom info to the Adobe window.

    'By Christos Samaras
    'http://www.myengineeringworld.net

    Dim strPDFName As String
    Dim lParent As Long
    Dim lFirstChildWindow As Long
    Dim lSecondChildFirstWindow As Long
    Dim lSecondChildSecondWindow As Long
    Dim dtStartTime As Date
    Dim strFType As String 'file extension type string ex DOC etc
    Debug.Print strpath

    'Modified for any file type = DOCX\JPG\ etc
    'Check if the PDF /DOCXpath is correct.
    If FileExists(strpath) = False Then
    MsgBox "No FIle named " & vbCrLf & strpath & " available at this time.!", vbInformation, "File not created at this time."
    Exit Sub
    End If

    'Get the PDF/DOCX file name from the full path.
    On Error Resume Next
    strPDFName = Mid(strpath, InStrRev(strpath, "\") + 1, Len(strpath))
    On Error GoTo 0
    'Check to see if PDF or DOCX or JPG
    strFType = UCase(Right(strpath, 3))

    Select Case strFType
    Case "PDF"
    Application.FollowHyperlink strpath ', NewWindow:=True
    Case "OCX"
    Application.FollowHyperlink strpath
    Case "DOC"
    Application.FollowHyperlink strpath
    Case "JPG"
    Application.FollowHyperlink strpath
    Case "PPT"
    ActivePresentation.FollowHyperlink strpath, NewWindow:=True
    Case "PPTX"
    ActivePresentation.FollowHyperlink strpath, NewWindow:=True
    Case "EXE"
    ActivePresentation.FollowHyperlink strpath, NewWindow:=True
    End Select
    'The following line depends on the apllication you are using.
    'For Word:
    'ThisDocument.FollowHyperlink strPDFPath, NewWindow:=True
    'For Power Point:
    'ActivePresentation.FollowHyperlink strPDFPath, NewWindow:=True
    'Note that both Word & Power Point pop up a security window asking
    'for access to the specified PDf file.
    'For Access:
    'If a docx or Doc use \'Application.FollowHyperlink strDocPath
    'if JPG use
    'Application.FollowHyperLink strJPGPath


    'For Excel:
    'ThisWorkbook.FollowHyperlink strPDFPath, NewWindow:=True
    'Find the handle of the main/parent window.
    dtStartTime = Now()
    Do Until Now() > dtStartTime + TimeValue("00:00:05")
    lParent = 0
    DoEvents
    'For Adobe Reader.
    'lParent = FindWindow("AcrobatSDIWindow", strPDFName & " - Adobe Reader")
    'For Adobe Professional.
    lParent = FindWindow("AcrobatSDIWindow", strPDFName & " - Adobe Acrobat Pro")
    If lParent <> 0 Then Exit Do
    Loop

    If lParent <> 0 Then

    'Bring parent window to the foreground (above other windows).
    SetForegroundWindow (lParent)

    'Find the handle of the first child window.
    dtStartTime = Now()
    Do Until Now() > dtStartTime + TimeValue("00:00:05")
    lFirstChildWindow = 0
    DoEvents
    lFirstChildWindow = FindWindowEx(lParent, ByVal 0&, vbNullString, "AVUICommandWidget")
    If lFirstChildWindow <> 0 Then Exit Do
    Loop


    'Find the handles of the two subsequent windows.
    If lFirstChildWindow <> 0 Then
    dtStartTime = Now()
    Do Until Now() > dtStartTime + TimeValue("00:00:05")
    lSecondChildFirstWindow = 0
    DoEvents
    lSecondChildFirstWindow = FindWindowEx(lFirstChildWindow, ByVal 0&, "Edit", vbNullString)
    If lSecondChildFirstWindow <> 0 Then Exit Do
    Loop

    If lSecondChildFirstWindow <> 0 Then

    'Send the zoom value to the corresponding window.
    SendMessage lSecondChildFirstWindow, WM_SETTEXT, 0&, ByVal strZoomValue
    PostMessage lSecondChildFirstWindow, WM_KEYDOWN, VK_RETURN, 0

    dtStartTime = Now()
    Do Until Now() > dtStartTime + TimeValue("00:00:05")
    lSecondChildSecondWindow = 0
    DoEvents
    'Notice the difference in syntax between lSecondChildSecondWindow and lSecondChildFirstWindow.
    'lSecondChildSecondWindow is the handle of the next child window after lSecondChildFirstWindow,
    'while both windows have as parent window the lFirstChildWindow.
    lSecondChildSecondWindow = FindWindowEx(lFirstChildWindow, lSecondChildFirstWindow, "Edit", vbNullString)
    If lSecondChildSecondWindow <> 0 Then Exit Do
    Loop
    If lSecondChildSecondWindow <> 0 Then

    'Send the page number to the corresponding window.
    SendMessage lSecondChildSecondWindow, WM_SETTEXT, 0&, ByVal strPageNumber
    PostMessage lSecondChildSecondWindow, WM_KEYDOWN, VK_RETURN, 0

    End If

    End If

    End If

    End If

    End Sub
    [Code/]

    Hope this helps

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2013, 07:06 PM
  2. Replies: 15
    Last Post: 09-06-2012, 06:25 PM
  3. Replies: 1
    Last Post: 03-07-2012, 09:00 AM
  4. Change of report layout
    By funsofinnih in forum Reports
    Replies: 1
    Last Post: 01-24-2012, 07:18 PM
  5. Can't change report name
    By kman42 in forum Reports
    Replies: 1
    Last Post: 10-19-2011, 02:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums