Results 1 to 4 of 4

Thread: [Access] Folder Path Issue

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2022
    Posts
    1

    [Access] Folder Path Issue

    I am new to using VB and I have a script I use to save an Access report as a PDF. I have it assigned to a button and no issues. When I try to use the same script to run when the report is loaded it gives me an error saying the folder path is invalid. Both paths are identical. Not sure what the issues is. I am trying to automate the reports for emailing and before I can continue, I need this to work.
    Code:
    Option Compare Database
    
    Function FileExist(FileFullPath As String) As Boolean
      Dim value As Boolean
      value = False
      If Dir(FileFullPath) <> "" Then
        value = True
      End If
      FileExist = value
    End Function
    
    Private Sub cmd_exportPDF_Click()
     
      Dim fileName As String, fldrPath As String, filePath As String
      Dim answer As Integer
      
      todayDate = Format(Date, "MMDDYYYY")
     
      fileName = "CSI Cheek" & todayDate 'filename for PDF file*
      fldrPath = "\\cidshare1.ellis.int\cid\#Activity\Reports" 'folder path where pdf file will be saved *
     
      filePath = fldrPath & "\" & fileName & ".pdf"
     
       
      On Error GoTo invalidFolderPath
      DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath
     
      MsgBox prompt:="PDF File exported to: " & vbNewLine & filePath, buttons:=vbInformation, Title:="Report Exported as PDF"
      Exit Sub
     
    invalidFolderPath:
      MsgBox prompt:="Error: Invalid folder path. Please update code.", buttons:=vbCritical
     
    End Sub
    
    
    Private Sub Report_Load()
     
      Dim fileName As String, fldrPath As String, filePath As String
      Dim answer As Integer
      
      todayDate = Format(Date, "MMDDYYYY")
     
      fileName = "CSI Cheek" & todayDate 'filename for PDF file*
      fldrPath = "\\cidshare1.ellis.int\cid\#Activity\Reports" 'folder path where pdf file will be saved *
     
      filePath = fldrPath & "\" & fileName & ".pdf"
     
       
      On Error GoTo invalidFolderPath
      DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath
     
      MsgBox prompt:="PDF File exported to: " & vbNewLine & filePath, buttons:=vbInformation, Title:="Report Exported as PDF"
      Exit Sub
     
    invalidFolderPath:
      MsgBox prompt:="Error2: Invalid folder path. Please update code.", buttons:=vbCritical
    
     
    End Sub

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,090

    Re: [Access] Folder Path Issue

    The error message is saying "Invalid folder path" because that is the hard-coded message in your error handler routine.

    Comment out the "On Error Goto..." line in the Sub that isn't working, try to run the code, and you should get a system generated error message that provides more specific details regarding the nature of the error and the line of code the error occurs on. Update the thread as appropriate.

    Good luck.

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,140

    Re: [Access] Folder Path Issue

    That # in your folder path could be an issue.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,342

    Re: [Access] Folder Path Issue

    Quote Originally Posted by jdc2000 View Post
    That # in your folder path could be an issue.
    It shouldn't, since "#" is a legal character in filenames/-paths (though i agree that it should be avoided)
    My money is actually more on "objectName:=Me.Name" or, since it's a share, write-access-issues
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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