Results 1 to 6 of 6
  1. #1
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51

    Viewing and Saving PDF using a button(VBA)

    I am trying to save and view pdf inside of my database. I want to do this through vba and a button.

    Here is my miserable code that doesnt work. It does open adobe but doesnt open file. I want to ultimately save paths to image in a table. I also want to have a form that allows combo or text boxes to build the paths and names of the pdf files for storage in a table or allows to retrieve specific pdf.

    Private Sub cmdEmpAdd_Click()




    Dim stDocName As String
    Dim MyRPT As String
    MyRPT = "33118TS"
    stDocName = """" & MyRPT & """"
    Dim PDFFILE As String
    PDFFILE = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers\Alberto Saenz" 'This field contains the text string with the full file path to the pdf'
    PDFFILE = """" & PDFFILE & """"
    Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe " & PDFFILE
    'MyRPT = Combo756
    stDocName = """" & MyRPT & """"
    PDFFILE = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers\Alberto Saenz\33118TS" 'This field contains the text string with the full file path to the pdf'
    PDFFILE = """" & PDFFILE & """"
    Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe " & PDFFILE


    End Sub

    Thanks

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    If you want to view files inside your database use a web browser control and set its source to the file location.
    Here's an example which will show you how it can be done
    https://access-programmers.co.uk/for...d.php?t=297837
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you dont want to view the pdf IN the database, instead use this code to open the reader (for ANY type of file):

    Paste this code into a module, and it will open ANY file in its native application.
    In a form put the field and a button to open it.

    if the file is myFile.pdf, will open it in acrobat
    if the file is myFile.doc, it will open the doc in Word
    if its just a file path, it will open in file explorer.
    etc..


    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

    usage:

    Code:
    sub btnOpenFile_click()
      OpenNativeApp ME.txtBox
    end sub

  4. #4
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51

    I can open pdf but cant build path

    Click image for larger version. 

Name:	2018-04-10 (2).png 
Views:	11 
Size:	24.0 KB 
ID:	33493

    Ok so I would like the end user to be able to select values from these comboboxes and than it would build the path to the file. That way when they click a view button it would display the file they have chosen.

    D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers\ Alberto Saenz / 4718TS.pdf
    Storage Path Driver Name Date and paperwork type

    D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Mixers\ 115 / 1154718DV.pdf
    Storage Path Mixer# Mixer#,Date and paperwork type

    D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers\Alberto Saenz/4718TS.pdf
    D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Mixers\115/1154718DV.pdf Actual Paths to File

    files are stored by week ending date or single date
    types of paperwork are three TS, DL, and DV

    Thanks

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    In your paths, modify the code to remove the spaces after some of the backslashes AND replace the forward slashes with backslashes

    Which approach are you going to use -internal web browser control or open as external file
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51
    I am using the external opening of the file. There are no spaces in my path was showing you the path and meaning. I cant get a path created from the combo box and text boxes using code. I need to create a path and put it into that hidden unbound text box so when view button is clicked the database know where to go to open file.

    Here are my tables and relationships
    Attached Thumbnails Attached Thumbnails 2018-04-10 (4).png  

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

Similar Threads

  1. Replies: 1
    Last Post: 03-17-2017, 08:32 AM
  2. Saving a Record Edit ONLY if button is clicked?
    By McArthurGDM in forum Forms
    Replies: 3
    Last Post: 06-01-2015, 09:33 PM
  3. Replies: 3
    Last Post: 04-22-2015, 04:35 AM
  4. Saving records when a button is pushed
    By LAazsx in forum Programming
    Replies: 1
    Last Post: 11-28-2010, 10:06 PM
  5. VB coding for saving when click on save button in form
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-04-2010, 11:11 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