Delete a file after creating and emailing it.

H

HighlanderMom

Hi,

I have Access 2003 database that prints a report to to PDF and then mails it
out. That is working just fine.

Now what I need is to be able to delete the once the email has been sent.

I was given this code, but I get an error message:
Private Sub Deletefile()
' This will delete the pdf file that is created for the email.
Dim fso As FileSystemObject 'Set a reference to
C:/Windows/System32/scrrun.dll
fso.Deletefile "H:/MYDOCS/rpt_Complaint_EmailPDF", True
End Sub

error:
91 variable or With block variable not set.

Any help would be appreciated.

Thanks!
 
D

Douglas J. Steele

Rather than adding the overhead of FSO, try:

Private Sub Deletefile()
Kill "H:/MYDOCS/rpt_Complaint_EmailPDF"
End Sub


If you're interested, the answer to your actual question is that you haven't
instantiated the reference to FSO:

Private Sub Deletefile()
Dim fso As FileSystemObject

Set fso = New FileSystemObject
fso.Deletefile "H:/MYDOCS/rpt_Complaint_EmailPDF", True

End Sub

or, if you prefer late binding (which means you don't have to set the
reference to scrrun.dll)

Private Sub Deletefile()
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")
fso.Deletefile "H:/MYDOCS/rpt_Complaint_EmailPDF", True

End Sub
 
H

HighlanderMom

Thank you very much! It worked and I really appreciate knowing what I was
doing wrong as well as the easier way to do it. I'll keep these for future
use too. :0)
--
HighlanderMom
"You should be careful what you wish for or you may get it."


Douglas J. Steele said:
Rather than adding the overhead of FSO, try:

Private Sub Deletefile()
Kill "H:/MYDOCS/rpt_Complaint_EmailPDF"
End Sub


If you're interested, the answer to your actual question is that you haven't
instantiated the reference to FSO:

Private Sub Deletefile()
Dim fso As FileSystemObject

Set fso = New FileSystemObject
fso.Deletefile "H:/MYDOCS/rpt_Complaint_EmailPDF", True

End Sub

or, if you prefer late binding (which means you don't have to set the
reference to scrrun.dll)

Private Sub Deletefile()
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")
fso.Deletefile "H:/MYDOCS/rpt_Complaint_EmailPDF", True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top