Hi All,
I have some code that resides in a button on a report that allows me to save a PDF version of this report. My problem is that if i have the destination directory open on windows explorer, i get a runtime 2501 "The output To action was cancelled" error.
Is there any way to check if the directory is already open, and cancel the output to, or close the window to avoid this error?
Here is my code:
I have some code that resides in a button on a report that allows me to save a PDF version of this report. My problem is that if i have the destination directory open on windows explorer, i get a runtime 2501 "The output To action was cancelled" error.
Is there any way to check if the directory is already open, and cancel the output to, or close the window to avoid this error?
Here is my code:
Code:
Private Sub CmdSavePDF_Click()
Dim MyFileName As String
Dim MyPath As String
'Dim CompanyName As String
'CompanyName = Me.CompanyName
If Dir("S:\Contracts\Geomatics LAB\Templates\Drafts\" & Me.CompanyName, vbDirectory) = "" Then
MkDir ("S:\Contracts\Geomatics LAB\Templates\Drafts\" & Me.CompanyName)
Else
'do nothing for the "C:\Text Files" directory already exists
'MsgBox "S:\Contracts\Geomatics LAB\Templates\Drafts\ & Me.CompanyName directory already exists"
End If
MyFileName = Format(Me.DateOutReq, "yyyy") & _
"-" & Format(Me.DateOutReq, "mm") & "-" & Format(Me.DateOutReq, "dd") & _
"-" & Me.CompanyName & "-ScheduleA" & ".pdf"
MyPath = "S:\Contracts\Geomatics LAB\Templates\Drafts\" & Me.CompanyName & "\"
DoCmd.OutputTo acOutputReport, "rptScheduleA", acFormatPDF, MyPath & MyFileName, False
End Sub