Writing out a CSV file getting Run-time error ‘75’: Path/File access error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AndyB2
    New Member
    • Dec 2011
    • 49

    Writing out a CSV file getting Run-time error ‘75’: Path/File access error

    Using Access 2010

    I need to write a CSV file where the number of fields on each record is not the same, requirement of the program we are feeding.

    Below is the code I am having I am getting the error: Run-time error 75: Path/File access error.

    Error is happening at “Open fileopen for Output as #1” (line 30)

    Code:
    Private Sub CB_RunQueryPrintReport_Click()
    Dim stDocName As String
    Dim Filename As String
    Dim i As Integer
    Dim test As String
    Dim MyDB As DAO.Database
    Dim REQ As DAO.Recordset
    Dim UDI As DAO.Recordset2
    
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    Set REQ = MyDB.OpenRecordset("Tbl_REQData", DB_OPEN_TABLE)
    Set UDI = MyDB.OpenRecordset("Tbl_UDIData", DB_OPEN_TABLE)
    
    
    DoCmd.Hourglass True
    DoCmd.SetWarnings False
    
    'Set tables before exporting
    DoCmd.OpenQuery "Qry_FindPanelParts"
    DoCmd.OpenQuery "Qry_PanelsToCut"
    DoCmd.OpenQuery "Qry_PanelsToCutAddOn"
    DoCmd.OpenQuery "Qry_PanelsToCutAddOn2"
    DoCmd.OpenQuery "Qry_PanelsToCutAddOn3"
    DoCmd.OpenQuery "Qry_PanelsToCutAddOn4"
    'DoCmd.OpenQuery "Qry_ChrParts_Req"
    'DoCmd.OpenQuery "Qry_ChrParts_UDI"
    
    
    Filename = "C:Cherry.csv"
    Open Fileopen For Output As #1
    REQ.MoveFirst
    UDI.MoveFirst
        Print #1, REQ("rowt"), ",", REQ("fld2"), ",", REQ("SEQ"), ",", REQ("part"), ",", REQ("fld5"), ",", REQ("Len"), ",", REQ("WID"), ",", REQ("fld8"), ",", REQ("fld9"), ","; REQ("fld10"), ","; REQ("fld11"), ","; REQ("fld12"), ",", REQ("Fld13")
        Print #1, UDI.rowt, ",", UDI.fld2, ",", UDI.SEQ, ",", UDI.fld4, ",", UDI.fld5, ",", UDI.Len, ",", UDI.WID, ",", UDI.fld8
    Close #1
    
    DoCmd.Hourglass False
    DoCmd.SetWarnings True
    
    
    End Sub
    I’m sure someone will be able answer this in their sleep.

    I the file is already created and is blank.

    Thanks in advance.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Fix may depend on the operating system (XP, Vista, etc...)
    This is normally due to lack of privilage to read/write/modify files in the directroy.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I don't know if this is a typo but
      C:Cherry.csv
      needs to be
      C:\Cherry.csv or C:\\Cherry.csv
      depending on if the backslash needs to be escaped.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Thnx Rabbit, missed that.

        Your first should work as that what I have used in the past for path names.

        In anycase, most I.T. block writing to the root directory of the boot drive (typically "C:\") since WinNT and since Windows Vista the default is to prevent anything accept system from writing to the root drive.

        So if the fix to the path doesn't work you'll still need to check into the security settings.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Andy, let me congratulate you first on a much better question :-)

          I suspect you have an issue with Require Variable Declaration, as it appears line #30 has an error trying to reference a variable that neither exists nor has been set - Fileopen. I suspect you intended to use :
          Code:
          Open Filename For Output As #1
          NB. Don't forget the earlier advice to specify the path of the file fully and correctly. "C:Cherry.c sv" refers to a file whose name is "Cherry.csv " and which is found in the C drives currently selected folder. As this hasn't been set in the code it is rather pot-luck where it will be looking for it.

          PS. It is always recommended to use a value returned by FreeFile() rather than the explicit value 1.
          Last edited by NeoPa; Dec 5 '12, 02:13 AM. Reason: Added PS.

          Comment

          Working...