bg3075
Civil/Environmental
- Feb 25, 2011
- 4
thread766-141175
Working off of the thread above, I am trying to have VBA code
1. Open a Select Query, on a Hyperlink field, based on a list box selection ("txtWellID")
2. Check if a PDF file exists for the item in "txtWellID" then
a. Open the hyperlink, or else
b. Display a MsgBox and close the query
I am a bit of a Virgin VBA coder, and have never used the "FileExists" method, but believe it to be what I need to accomplish this task. Below is a rough sample of my attempt. It was working to open the hyperlink before adding "FileExists" method, so I know that portion of code was working; but I did change around to add "FileExists". Can anyone modify for me please?
Working off of the thread above, I am trying to have VBA code
1. Open a Select Query, on a Hyperlink field, based on a list box selection ("txtWellID")
2. Check if a PDF file exists for the item in "txtWellID" then
a. Open the hyperlink, or else
b. Display a MsgBox and close the query
I am a bit of a Virgin VBA coder, and have never used the "FileExists" method, but believe it to be what I need to accomplish this task. Below is a rough sample of my attempt. It was working to open the hyperlink before adding "FileExists" method, so I know that portion of code was working; but I did change around to add "FileExists". Can anyone modify for me please?
Code:
Private Sub cmdOK_Click()
'Opens Groundwater Trend Charts, based on hyperlinks in the table "Well_info"
Dim qryTrendChartLinks As Hyperlink
Dim txtWellID As String
txtWellID = Forms!frmWellTrendChartsDialog!txtWellID
On Error GoTo ErrorHandler
Set FSO = New FileSystemOBject
DoCmd.OpenQuery ("qryTrendChartLinks")
If FSO.FileExists("D:\Trend Charts" & "txtWellID" & ".pdf") Then
DoCmd.RunCommand acCmdOpenHyperlink
DoCmd.Close acQuery, "qryTrendChartLinks", acSaveNo
Else
'If Not ("qryTrendChartLinks") Like "*" Then
MsgBox ("Could not find a report")
ErrorHandler: MsgBox ("Cannot find Trend Chart")
DoCmd.Close acQuery, "qryTrendChartLinks", acSaveNo
End If
End Sub