Results 1 to 5 of 5
  1. #1
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77

    MakeDir Crashes on Initial Output to PDF

    when it runs, it creates all the directories and access crashes. in the directory there is a .tmp file (pdf temp file). restart access since directories are now there, it will create the PDF files as planned. Thanks




    Code:
    Private Sub CreatePDF_Click()DoCmd.RunCommand acCmdSaveRecord
    
    
    Dim UserVenuePath As String
    Dim strFilePath As String
    Dim strFileName As String
    Dim strReport As String
    Dim Venue As String
    
    
    UserVenuePath = DLookup("[FilePath]", "tbl_SystemInfo", "[SystemInfoID] = 1")
    Venue = DLookup("[Venue]", "tbl_SystemInfo", "[SystemInfoID] = 1")
    strFilePath = UserVenuePath & Environ("username") & "\OneDrive - Caterers In The Park\" & Venue & "\Contracts\" & Format(Forms!frm_Contract.DateofFunction, "MM-DD-yyyy") & "\" & Forms!frm_Contract.DayTimeFunction & "\"
    strFileName = Forms!frm_Contract.NameonContract & ".pdf"
    
    
    MakePDF = MsgBox(strFilePath, vbOKCancel, "Create PDF for " & strFileName)
    If MakePDF = vbOK Then
    
    
    If FolderExists(strFilePath) = False Then
              Call MakeDir(strFilePath)
    Else
              MsgBox "This folder already exists.", vbInformation, "Folder Exists"
    End If
    
    
    'First let's open the report
    strReport = "rpt_Contract"
    'DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = [Forms]![frm_Contract]![ContractsID]", acWindowNormal
    
    
    'Now let's save the open report to .PDF
    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False
    'DoCmd.Close acReport, strReport
    
    
    'Display Message
    MsgBox "New file has created successfully in the new folder!", vbInformation, "VBAF1"
    
    
    End If
    
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Perhaps put a DoEvents between creating a folder and outputting to said folder?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    This is the custom function I used for multi-level directory creation (also works with UNC paths):
    Code:
    Public Sub MyMkDir(sPath As String)
        Dim iStart          As Integer
        Dim aDirs           As Variant
        Dim sCurDir         As String
        Dim i               As Integer
     
        If sPath <> "" Then
            aDirs = Split(sPath, "\")
            If Left(sPath, 2) = "\\" Then
                iStart = 3
            Else
                iStart = 1
            End If
     
            sCurDir = Left(sPath, InStr(iStart, sPath, "\"))
     
            For i = iStart To UBound(aDirs)
                sCurDir = sCurDir & aDirs(i) & "\"
                If Dir(sCurDir, vbDirectory) = vbNullString Then
                    MkDir sCurDir
                End If
            Next i
        End If
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    i compiled, compacted and repaired a few times and its working again. something screwy i guess

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Call MakeDir Failing on certain systems
    By jazzy in forum Programming
    Replies: 20
    Last Post: 05-16-2022, 06:50 PM
  2. Replies: 4
    Last Post: 04-23-2014, 04:35 PM
  3. Replies: 4
    Last Post: 12-30-2013, 05:51 PM
  4. Need help on initial design
    By allykid in forum Database Design
    Replies: 2
    Last Post: 11-09-2010, 01:46 PM
  5. Initial Parameter Value?
    By justgeig in forum Queries
    Replies: 7
    Last Post: 12-08-2009, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums