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