Whys does the second "If Len(Dir(Filenam e)) > 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.OpenRecordse t(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(Filenam e)) > 0 Then ' Returns True
CostSheet_TAB.V isible = True
CostSheet.Visib le = True
CostSheet.Sourc eDoc = Filename
CostSheet.Actio n = acOLECreateLink
Else
' Hide CostSheet TAB
CostSheet_TAB.V isible = False
End If
' Load Check Sheet into Form.
Filename = CheckSheetPath + SerialNum + ".pdf"
If Len(Dir(Filenam e)) > 0 Then ' Does not return True
CheckSheet_TAB. Visible = True
CheckSheet.Visi ble = True
CheckSheet.Load File Filename
CheckSheet.setS howToolbar (False)
CheckSheet.Heig ht = 10000
CheckSheet.Widt h = 12000
CheckSheet.setV iew ("FullScreen ")
Else
CheckSheet_TAB. Visible = False
End If
' close recordset
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub
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.OpenRecordse t(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(Filenam e)) > 0 Then ' Returns True
CostSheet_TAB.V isible = True
CostSheet.Visib le = True
CostSheet.Sourc eDoc = Filename
CostSheet.Actio n = acOLECreateLink
Else
' Hide CostSheet TAB
CostSheet_TAB.V isible = False
End If
' Load Check Sheet into Form.
Filename = CheckSheetPath + SerialNum + ".pdf"
If Len(Dir(Filenam e)) > 0 Then ' Does not return True
CheckSheet_TAB. Visible = True
CheckSheet.Visi ble = True
CheckSheet.Load File Filename
CheckSheet.setS howToolbar (False)
CheckSheet.Heig ht = 10000
CheckSheet.Widt h = 12000
CheckSheet.setV iew ("FullScreen ")
Else
CheckSheet_TAB. Visible = False
End If
' close recordset
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub
Comment