ks******@mappingalaska.com (Avalanche) wrote in message news:<9b**************************@posting.google. com>...
Greetings all.
I'm building a database (Access 2003) of applicants. Included in this
database I would like to include the PDF applications for individuals
in the database, accessable from a form or table within Access (not a
hyperlink). Any ideas on how to make this work?
Thanks...
If you use the default installation path for Reader you can do
something like:
'Setup code to handle monitoring when Acrobat Reader closes
'Code from Microsoft KB article Q129796
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Const STILL_ACTIVE = &H103
Dim retval As Long
Function GetAcroPath() As String
Dim I As Integer
Dim strAcroDir(5) As String
Dim strLocatedAcroDir As String
strAcroDir(1) = "C:\Program Files\Adobe\Acrobat 3.0\Reader\"
strAcroDir(2) = "C:\Program Files\Adobe\Acrobat 4.0\Reader\"
strAcroDir(3) = "C:\Program Files\Adobe\Acrobat 5.0\Reader\"
strAcroDir(4) = "C:\Program Files\Adobe\Acrobat 6.0\Reader\"
'strAcroDir(5) = "C:\Program Files\Adobe\Acrobat 7.0\Reader\"
strLocatedAcroDir = ""
For I = 4 To 1 Step -1
If Dir(strAcroDir(I), vbDirectory) <> "" Then
strLocatedAcroDir = strAcroDir(I)
Exit For
End If
Next I
GetAcroPath = strLocatedAcroDir & "AcroRd32.exe"
End Function
Public Function ExecCmd(cmdline$)
Dim ret As Long
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
'Save the value so the status can be checked later
retval = ret
ExecCmd = ret&
End Function
Private Sub lboPDFFiles_DblClick(Cancel As Integer)
Dim strFile As String
Dim strAcroReaderPath As String
'Preview the file with Adobe Acrobat Reader. Make sure it is closed
'before creating a new file.
If IsNull(lboPDFFiles.Value) Then Exit Sub
strAcroReaderPath = GetAcroPath()
If strAcroReaderPath = "" Then
MsgBox ("Cannot find directory for Acrobat Reader.")
Exit Sub
End If
If Dir(strAcroReaderPath, vbNormal) <> "" Then
strFile = "C:\MyPDFFiles\" & lboPDFFiles.Value
retval = ExecCmd(strAcroReaderPath & " " & strFile)
Else
MsgBox ("Cannot find Acrobat Reader program.")
End If
End Sub
Code in form:
'See if the preview is open
If retval <> 0 Then
boolAns = GetExitCodeProcess(proc.hProcess, retval&)
If retval = STILL_ACTIVE Then
MsgBox ("Acrobat Reader needs to be closed before the new file can
be created.")
Exit Sub
End If
End If
Call CloseHandle(proc.hProcess)
retval = 0
Note: I plucked this code out of a lot of code so it may be incomplete
or have extra code. The extra precaution about Reader being open was
that when editing was done on the form that overwrote a previous file,
Reader having that file open already caused an error. Also, be aware
that this code was written for Access 97. I hope this is similar to
what you're trying to do.
James A. Fortune