Whys does the second "If Len(Dir(Filename)) > 0 Then" function not work in this code, the first one is ok. The files DO exist and both should return 'true'. If I REM the second IF THEN, ELSE, ENDIF statements, it loads the pdf file ok!
Private Sub Form_Current()
' Update Cost Sheet, Check Sheet and drive History data on NCR change
Dim db As Database
Dim rs As Recordset
Dim StrSQL As String
Dim CostSheetPath As String
Dim CheckSheetPath As String
Dim SerialNum As String
Dim Product As String
Dim Filename
Product = Nz(Forms!NCR![ProductCombo])
Set db = CurrentDb
StrSQL = "SELECT [Product Table].[Check Sheet Path], [Product Table].[Cost Sheet Path]FROM [Product Table]WHERE [Product Table].[Product/Service]= '" & Product & "'"
Set rs = db.OpenRecordset(StrSQL)
If rs.EOF = False Then
CostSheetPath = Nz(rs![Cost Sheet Path])
CheckSheetPath = Nz(rs![Check Sheet Path])
Else
CostSheetPath = ""
CheckSheetPath = ""
End If
SerialNum = Nz(Forms!NCR![Serial Number])
' Load Cost Sheet into Form if it exists otherwise hide it
Filename = CostSheetPath + SerialNum + ".xls"
If Len(Dir(Filename)) > 0 Then ' Returns True
CostSheet_TAB.Visible = True
CostSheet.Visible = True
CostSheet.SourceDoc = Filename
CostSheet.Action = acOLECreateLink
Else
' Hide CostSheet TAB
CostSheet_TAB.Visible = False
End If
' Load Check Sheet into Form.
Filename = CheckSheetPath + SerialNum + ".pdf"
If Len(Dir(Filename)) > 0 Then ' Does not return True
CheckSheet_TAB.Visible = True
CheckSheet.Visible = True
CheckSheet.LoadFile Filename
CheckSheet.setShowToolbar (False)
CheckSheet.Height = 10000
CheckSheet.Width = 12000
CheckSheet.setView ("FullScreen")
Else
CheckSheet_TAB.Visible = False
End If
' close recordset
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub