Results 1 to 2 of 2
  1. #1
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43

    Post Button in subform detail area to open a pdf file based on link in a table


    Dear Experts,

    Good day!

    I had a problem on how to modify the code i found in a forum. This is a piece of code where working in main form only.
    But what i want is to put the button inside the subform detail and when they hit click it will pop up the pdf file.
    I do hope that experts can see this problem of mine and help me out of this problem.

    I attached herewith the screenshots of my form and a code behind the button

    Below is the code in a module

    Thank you in advance experts!

    Code:
    Option Compare Database
    Option Explicit
    
    Public strDefImportDir As String
    
        Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
            "GetOpenFileNameA" (pOpenfilename As Openfilename) As Long
    
    
        Public Type Openfilename
             lStructSize As Long
             hwndOwner As Long
             hInstance As Long
             lpstrFilter As String
             lpstrCustomFilter As String
             nMaxCustFilter As Long
             nFilterIndex As Long
             lpstrFile As String
             nMaxFile As Long
             lpstrFileTitle As String
             nMaxFileTitle As Long
             lpstrInitialDir As String
             lpstrTitle As String
             Flags As Long
             nFileOffset As Integer
             nFileExtension As Integer
             lpstrDefExt As String
             lCustData As Long
             lpfnHook As Long
             lpTemplateName As String
        End Type
    
    Public Function FindFileName(strType As String, strDialogTitle, strNewFile As String)
    On Error Resume Next
             Dim openfile As Openfilename
             Dim lReturn As Long
             Dim sFilter As String
             openfile.lStructSize = Len(openfile)
             sFilter = strType
             openfile.lpstrFilter = sFilter
             openfile.nFilterIndex = 1
             openfile.lpstrFile = String(255, 0)
             openfile.nMaxFile = Len(openfile.lpstrFile) - 1
             openfile.lpstrFileTitle = openfile.lpstrFile
             openfile.nMaxFileTitle = openfile.nMaxFile
             openfile.lpstrInitialDir = strDefImportDir
             openfile.lpstrTitle = strDialogTitle
             openfile.Flags = 0
             lReturn = GetOpenFileName(openfile)
             If lReturn > 0 Then
                strNewFile = Trim(openfile.lpstrFile)
            End If
            
    exit_proc:
        Exit Function
    
    err_proc:
        MsgBox Err.Description
        Resume exit_proc
     
    End Function
    
    Public Function FindSavePDFFile(DocumentNo As String)
    
    
    On Error GoTo err_proc
        Dim strPDFFile As String
        Dim SaveFileName As String
        Dim strDir As String
        Dim strMessage As String
        
        FindFileName "PDF files (*.PDF)" & Chr(0) & "*.PDF", _
                     "Locate PDF File for Current Record", strPDFFile
        If strPDFFile = "" Then GoTo exit_proc
        strDir = Nz(DLookup("PDFsFolder", "tblPDF", "PdfId = 1"), "")
        If strDir = "" Then
            MsgBox "PDF folder not set up in Operation Manual table", vbExclamation
            Exit Function
        End If
        
        If Dir(strDir, vbDirectory) = "" Then MkDir strDir
        SaveFileName = strDir & No & "_" & DocumentNo & "_" & RevisionNo & ".pdf"
        
        If Dir(SaveFileName) <> "" Then
            strMessage = SaveFileName & " already exists." & Chr(13) & Chr(13) & _
                       "Do you want to replace the existing file?"
            If MsgBox(strMessage, vbYesNo + vbDefaultButton2 + vbQuestion, "File Exists") = vbNo Then Exit Function
            Kill SaveFileName
        End If
        FileCopy strPDFFile, SaveFileName
        
    exit_proc:
        Exit Function
        
    err_proc:
        MsgBox Err.Description
        Resume exit_proc
    End Function
    Attached Thumbnails Attached Thumbnails PDFSearchCode1.jpg   PDFSearchCode2.JPG   PDFSearchCode3.JPG  

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What happens when you try? Do you get an error? If so, what is it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2015, 05:49 PM
  2. Not able to sort in detail area
    By boywonder381 in forum Reports
    Replies: 7
    Last Post: 09-21-2014, 09:44 PM
  3. Detail area of form help
    By Darkmatter5 in forum Forms
    Replies: 1
    Last Post: 07-10-2012, 04:28 PM
  4. Replies: 9
    Last Post: 02-22-2012, 07:30 PM
  5. Sums in Detail area of report
    By Rick West in forum Reports
    Replies: 2
    Last Post: 12-01-2009, 07:15 PM

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