With this code, I can open Word and Excel files, but not PDF. Please let me know what I'm doing wrong. (I tried changing strProg = "C:\Acrobat.lnk" including to a .exe file but nothing happens when I click the Open button)
---------------------------------------------------
Private Sub cmdOpen_Click()
Dim sSourcePath As String
Dim strProg As String
Dim objword As Object
Dim strFile As String
Dim XL As Object
sSourcePath = Me.FilePath
DoCmd.RunCommand acCmdSaveRecord
If fIsFileDIR(sSourcePath) = -1 Then
Select Case ParseFileName(sSourcePath, 3)
Case "xls"
Set XL = CreateObject("Excel.Application")
If IsNull(Me.FilePath) Then
MsgBox "You haven't Attached a File"
Else
With XL.Application
.Visible = True
.workbooks.Open Me.FilePath
End With
Set XL = Nothing
End If
Case "doc"
Set objword = CreateObject("Word.Application")
strFile = Me.FilePath
objword.Visible = True
objword.Documents.Open strFile
'--------------------------------------------------
Case "pdf"
'Open File
strProg = "C:\Acrobat.lnk"
Call Shell(strProg & " " & sSourcePath, vbMaximizedFocus)
Case Else
MsgBox "File type not recognised"
End Select
Else
MsgBox "File cannot be found. Please check the file path. ", vbExclamation
End If
End Sub
---------------------------------------------------
Private Sub cmdOpen_Click()
Dim sSourcePath As String
Dim strProg As String
Dim objword As Object
Dim strFile As String
Dim XL As Object
sSourcePath = Me.FilePath
DoCmd.RunCommand acCmdSaveRecord
If fIsFileDIR(sSourcePath) = -1 Then
Select Case ParseFileName(sSourcePath, 3)
Case "xls"
Set XL = CreateObject("Excel.Application")
If IsNull(Me.FilePath) Then
MsgBox "You haven't Attached a File"
Else
With XL.Application
.Visible = True
.workbooks.Open Me.FilePath
End With
Set XL = Nothing
End If
Case "doc"
Set objword = CreateObject("Word.Application")
strFile = Me.FilePath
objword.Visible = True
objword.Documents.Open strFile
'--------------------------------------------------
Case "pdf"
'Open File
strProg = "C:\Acrobat.lnk"
Call Shell(strProg & " " & sSourcePath, vbMaximizedFocus)
Case Else
MsgBox "File type not recognised"
End Select
Else
MsgBox "File cannot be found. Please check the file path. ", vbExclamation
End If
End Sub