CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2011
    Posts
    5

    bad file name or number

    what im trying to do is make the program check for files if they are there then do the commands and if not send an email it only ever does one if statement and bombs out on any other i get error saying bad filename or number heres my code
    WOrks order section
    Dim strSpecNameDrwgMF As String
    Dim strManvDrwg As String
    Dim strDistDrwgMF As String
    Dim strSubjectDrwgMF As String
    Dim strMsgDrwgMF As String

    '******write log file*********
    Open "C:/nightlyreports.txt" For Append As #1 ' Open file to read,
    Print #1, Now(); "changecont open"
    Close #1

    strSpecNameDrwgPO = "purvdrwg import specification"
    strSpecNameExcepPO = "pur-except import specification"
    strPath = "\\Kevingriggs\user\AccessTemp\"
    strPurvDrwg = "purvdrwg"
    strPurExcept = "purexcept"
    strExtn = ".txt"
    strExcel = "excel"
    strDistDrwgPO = "k.griggs@aim-henshalls.co.uk"
    strDistExceptPO = "k.griggs@aim-henshalls.co.uk"
    strSubjectDrwgPO = "Parts on Order at incorrect Issue"
    strSubjectExceptPO = "Expedite Purchase Order Lines"
    StrMsgDrwgPO = "The parts detailed in the attached Excel file are showing a conflict between the part issue and the part issue on the PO. Please check and amend as required"
    strMsgExceptPO = "The required dates for the parts detailed in the attached Excel files are sooner than the PO date."
    'strDay = Format(Now(), "ddd")
    ' Works Order Section
    strSpecNameDrwgMF = "manvdrwg import specification"
    strManvDrwg = "manvdrwg"
    strDistDrwgMF = "k.griggs@aim-henshalls.co.uk"
    strSubjectDrwgMF = "Works Orders at incorrect issue."
    strMsgDrwgMF = "The parts detailed in the attached Excel file are showing a conflict between the part issue and the part issue on the Works Order. Please check and amend as required"
    strDistcheck = "k.griggs@aim-henshalls.co.uk"
    strsubjectcheck = "ERROR"
    strmsgnopurvdrwg = "ChangeCont-2000 was unable to continue due to: File \\Kevingriggs\user\AccessTemp\purvdrwg.txt Not found"
    strmsgnopurexcept = "ChangeCont-2000 was unable to continue due to: File \\Kevingriggs\user\AccessTemp\purexcept.txt Not found"
    strmsgnopurexcept = "ChangeCont-2000 was unable to continue due to: File \\Kevingriggs\user\AccessTemp\ManvDrwg.txt Not found"

    If Dir("\\Kevingriggs\user\AccessTemp\purvdrwg.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnopurvdrwg, False
    ElseIf Dir("\\kevingrggs\user\accesstemp\purexcept.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnopurexcept, False
    ElseIf Dir("\\kevingrggs\user\accesstemp\manvdrwg.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnoManvDrwg, False
    Else
    'If strDay = "thu" Then
    DoCmd.DeleteObject acTable, strPurvDrwg
    DoCmd.TransferText acImportDelim, strSpecNameDrwgPO, strPurvDrwg, strPath & strPurvDrwg & strExtn, True
    DoCmd.SendObject acOutputQuery, strPurvDrwg & strExcel, acFormatXLS, strDistDrwgPO, , , strSubjectDrwgPO, StrMsgDrwgPO, False

    '******write log file*********
    Open "C:/nightlyreports.txt" For Append As #1 ' Open file to read,
    Print #1, Now(); "changecont closing"
    Close #1

    DoCmd.DeleteObject acTable, strPurExcept
    DoCmd.TransferText acImportDelim, strSpecNameExcepPO, strPurExcept, strPath & strPurExcept & strExtn, True
    DoCmd.SendObject acOutputQuery, strPurExcept & strExcel, acFormatXLS, strDistExceptPO, , , strSubjectExceptPO, strMsgExceptPO, False
    'DoCmd.DeleteObject acTable, "manvdrwg_importerrors"
    DoCmd.Quit


    DoCmd.DeleteObject acTable, strManvDrwg
    DoCmd.TransferText acImportDelim, strSpecNameDrwgMF, strManvDrwg, strPath & strManvDrwg & strExtn, True
    DoCmd.SendObject acOutputQuery, strManvDrwg & strExcel, acFormatXLS, strDistDrwgMF, , , strSubjectDrwgMF, strMsgDrwgMF, False
    DoCmd.Quit
    End If
    DoCmd.Quit
    End Sub

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: bad file name or number

    Well, if you really use "C:/nightlyreports.txt" as filename for your log then there is where the program crashes.
    You HAVE to use the backslash, so the name must be "C:\nightlyreports.txt". Otherwise your program will crash when opening this nonexisting path.

  3. #3
    Join Date
    Jan 2011
    Posts
    5

    Re: bad file name or number

    cheers but it crashes on the line after else if?

  4. #4
    Join Date
    Jan 2011
    Posts
    5

    Re: bad file name or number

    i mean the else if line

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: bad file name or number

    Why would you think this READS a file?

    Code:
    Open "C:/nightlyreports.txt" For Append As #1 ' Open file to read,
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: bad file name or number

    Quote Originally Posted by dglienna View Post
    Why would you think this READS a file?

    Code:
    Open "C:/nightlyreports.txt" For Append As #1 ' Open file to read,
    Good question I would expect that line to create a file in the current directory named "C:/nightlyreports.txt" if such file does not already exist or crash.

    In no case would it open a file for reading.

    As to the error which Else IF are you referring to? From what I can tell in the unformatted code the 2 else if statements look ok.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: bad file name or number

    Have you tried removing the slash in
    Code:
    Open "C:/nightlyreports.txt" For Append As #1 ' Open file to read
    The slash is a illegal character in a file name hence the error bad file name.

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: bad file name or number

    Because it won't work!
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: bad file name or number

    btw guys even though the comment says read he is not trying to read from the file. He is just appeneding to it so the mode is ok, comment is wrong but does nothing to the code. / is an issue.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Jan 2011
    Posts
    5

    Re: bad file name or number

    yeah im talking about this part
    If Dir("\\Kevingriggs\user\AccessTemp\purvdrwg.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnopurvdrwg, False
    ElseIf Dir("\\kevingrggs\user\accesstemp\purexcept.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnopurexcept, False
    ElseIf Dir("\\kevingrggs\user\accesstemp\manvdrwg.txt") = "" Then
    DoCmd.SendObject acSendNoObject, , , strDistcheck, , , strsubjectcheck, strmsgnoManvDrwg, False
    Else

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: bad file name or number

    Looks like you missed a letter in your path name in the 2 else if statements.
    The first one is Kevinriggs but the other two are Kevinrggs.

    btw why have you hard coded the path rather than use the variable you defined earlier?

    Code:
    strPath = "\\Kevingriggs\user\AccessTemp\"
    I would have used

    Code:
    ElseIf Dir(strPath & "purexcept.txt") = "" Then
    Last edited by DataMiser; January 18th, 2011 at 06:39 AM.
    Always use [code][/code] tags when posting code.

  12. #12
    Join Date
    Jan 2011
    Posts
    5

    Re: bad file name or number

    cheers, this was because i was going back on an old access file created by my boss a while back and i had not seen that string, thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured