DIR(Filename) Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Codebug
    New Member
    • Feb 2008
    • 25

    DIR(Filename) Question

    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
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Shouldn' t these
    Code:
    ...
    Filename = CostSheetPath + SerialNum + ".xls"
    ...
    Filename = CheckSheetPath + SerialNum + ".pdf"
    ...
    be

    Code:
    ...
    Filename = CostSheetPath & SerialNum & ".xls"
    ...
    Filename = CheckSheetPath & SerialNum & ".pdf"
    ...

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      Don't forget you can set breakpoints so the code stops during execution and you can hover the mouse over variables and see their contents

      You can even make a change in you code while the code has stoped at the breakpoint and then drag the execution point to the line before the change and continue execution from there. Saves stopping and restarting the program everytime just to make a change and see the effects.
      I discovered that trick by accident one day while puzzling over a bug and fooling around with the mouse while I was thinking

      Comment

      • Codebug
        New Member
        • Feb 2008
        • 25

        #4
        Solved the problem

        Id forgotten that i had set another event to load the pdf.


        In fact the path in th above code didnt exist, but I was fooled because it loaded the pdf ok!

        Comment

        Working...