File Path

  • Thread starter Thread starter JD
  • Start date Start date
J

JD

In my Access 2003 application I need to view a document (an application that
has been scanned and saved as a .pdf or word document, which ever will work
best) with each record.
What would be the best way to open a dialog, select the correct file, save
the path and then be able to view the document when the record is visible
within a form?
Thank you for your help..
 
For PDF files I've found that the Windows API ShellExecute function works
best to open the file. Paste the following module into your database:

Option Compare Database
Option Explicit

Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nshowcm As Long)

Sub ShellToFile(strPath As String, ByVal lngHwnd As Long)

Dim lngRetVal As Long

lngRetVal = ShellExecute(lngHwnd, "open", strPath, _
vbNullString, CurDir, 1)

If lngRetVal < 32 Then
MsgBox "Unable to open file " & strPath, vbInformation, "Warning"
End If

End Sub

Call it by passing the path to the file, as returned by the common dialogue,
and the value returned by the Hwnd property of the current window into the
ShellToFile Function. You can also open Word files with this. In fact it
should open any file type associated with an application.

Ken Sheridan
Stafford, England
 
Thank you. I was able to make it work.
Ken Sheridan said:
For PDF files I've found that the Windows API ShellExecute function works
best to open the file. Paste the following module into your database:

Option Compare Database
Option Explicit

Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal _
hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal _
lpParameters As String, ByVal lpDirectory As String, ByVal nshowcm As
Long)

Sub ShellToFile(strPath As String, ByVal lngHwnd As Long)

Dim lngRetVal As Long

lngRetVal = ShellExecute(lngHwnd, "open", strPath, _
vbNullString, CurDir, 1)

If lngRetVal < 32 Then
MsgBox "Unable to open file " & strPath, vbInformation, "Warning"
End If

End Sub

Call it by passing the path to the file, as returned by the common
dialogue,
and the value returned by the Hwnd property of the current window into the
ShellToFile Function. You can also open Word files with this. In fact it
should open any file type associated with an application.

Ken Sheridan
Stafford, England
 
Back
Top