'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"
** this is the database query
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT DISTINCT KJU250 FROM Q_¿‹ ", _
dbOpenForwardOnly, dbReadOnly)
** here I set query
Set qd = db.QueryDefs("Q_¿‹")
strSQL = Replace(qd.SQL, ";", "")
Do Until rs.EOF
** I want to create folder which is auto created and save pdf file in this folder.
** If I run this program now, folder and pdf file are
** generated separately.
** I want to save my pdf file into the auto-generated 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"
** Folder is generated automatically - I want to save
** `Do unitl rs.EOF pdf` in MkDir directory.
filepath = "C:\Lƒf[ƒ^\" & Format(Date, "yyyymmdd") & "_" & rs!KJU250
If Dir(filepath, vbDirectory) = "" Then
MkDir filepath
End If
rs.MoveNext
Loop
qd.SQL = strSQL & ";"
rs.Close
'20220630