I want to save my pdf file in automatically generated folder. In this code pdf file is generated outside of folder

Viewed 54

i want to save my pdf file in the folder(MkDir).which is generated outside of the folder. please tell me how I can save the pdf file in Dir.

'20220630
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim qd As DAO.QueryDef
    Dim strFilter As String
    Dim filepath As String
    Dim strSQL As String
 
    'strFilter = "¿‹“ú >= #" & Format(Date,"yyyy/mm") & "/01# AND " & _
    '            "¿‹“ú < #" & Format(DateAdd("m",1,Date),"yyyy/mm") & "/01"
 
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT DISTINCT KJU250 FROM Q_¿‹ ", _
                              dbOpenForwardOnly, dbReadOnly)
     
    Set qd = db.QueryDefs("Q_¿‹")
    strSQL = Replace(qd.SQL, ";", "")
    
      filepath = "C:\Lƒf[ƒ^\" & Format(Date, "yyyymmdd") & "_" & rs!KJU250
     
       If Dir(filepath, vbDirectory) = "" Then
       MkDir filepath

       End If
      
       
     Do Until rs.EOF
        *'i want to save that pdf file in the MkDir directory which is autogenerated folder*

        qd.SQL = strSQL & " WHERE " & strFilter & "  AND SEIKYUCD=" & rs!SEIKYUCD
        
       qd.SQL = strSQL & " WHERE KJU250=" & rs!KJU250
        DoCmd.OutputTo acOutputReport, "R_¿‹‘", acFormatPDF, _
            \Lƒf[ƒ^\" & Format(Date, "yyyymmdd") & "_" & rs!KJU250 & ".pdf"
      
            
        rs.MoveNext
        
    Loop
  
 
    qd.SQL = strSQL & ";"
    rs.Close
'20220630
1 Answers

How about using your filepath:

DoCmd.OutputTo acOutputReport, "R_¿‹‘", acFormatPDF, filepath & ".pdf"
Related