hiiiiiii all
i have report need to save it by creating Yearly folders and monthly subfolders.
i try to use this code :
but it gives me Run Time Error '2501' in the line:
please help me to get solution
i have report need to save it by creating Yearly folders and monthly subfolders.
i try to use this code :
Code:
Private Sub apdfNew1_Click()
Dim strFolderYear As String
Dim strFolderMonth As String
Dim myFileNx As String
Dim lngPK As Long 'change data type if yours is different
'set variable to current record ID
lngPK = Me.OrderID
Me.Requery
'return form to original record
With Me.RecordsetClone
.FindFirst "OrderID = " & lngPK
' 'if your key field is text use this line instead
' '.FindFirst "OrderID = " & Chr(34) & lngPK & Chr(34)
' If .NoMatch Then 'just in case another user deleted it in the interim
' MsgBox "Record not found!", vbCritical
' Else 'go to that record
Me.Bookmark = .Bookmark
' End If
End With
strFolderName = CurrentProject.Path & "\" & Format(Me.OrderDate, "yyyy") & "\" ' folder to save
strFolderMonth = strFolderName & Format(Me.OrderDate, "mmmm yyyy") & "\" ' folder to save
If Len(Dir(strFolderYear, vbDirectory)) = 0 Then
MkDir (strFolderYear)
If Len(Dir(strFolderMonth, vbDirectory)) = 0 Then
MkDir (strFolderMonth)
End If
End If
myFileNx = Format(Me.OrderDate, "dddd dd mmmm yyyy") & " - " & Me.PtName & ".pdf"
DoCmd.OpenReport "MainRpt", acViewPreview, , "OrderID = " & OrderID, acHidden
DoCmd.OutputTo acOutputReport, "MainRpt", acFormatPDF, strFolderMonth & myFileNx, True
DoCmd.RunMacro "RptClose"
'Call Shell("explorer.exe " & str_folder, vbNormalFocus)
End Sub
but it gives me Run Time Error '2501' in the line:
Code:
DoCmd.OutputTo acOutputReport, "MainRpt", acFormatPDF, strFolderMonth & myFileNx, True
please help me to get solution