I have a buton that does a number of things including sending an email. However, if, for whatever reason, a file wasn't deleted on a previous action I get an error message. I tried to fix that but then if there is no file I get an error message that there is no file found. Is there a way to just supress the error message so that the code continues whether the file exists or not.
Dim strEmail As String
Dim rstEmail As DAO.Recordset
Dim EmailApp As Object
Dim NameSpace As Object
Dim EmailSend As Object
Set rstEmail = CurrentDb.OpenRecordset("Addresses")
Do Until rstEmail.EOF
strEmail = strEmail & rstEmail("EmailAddress") & ";"
rstEmail.MoveNext
Loop
If Right(strEmail, 1) = ";" Then
strEmail = Left(strEmail, Len(strEmail) - 1)
End If
strPath = DLookup("TextPath", "Filepath")
Kill strPath (this fixed my first problem but now if there is no file I get an error)
DoCmd.OutputTo acReport, "Email", acFormatRTF, strPath
Open strPath For Input As #1
Do Until EOF(1)
Line Input #1, strTemp
strBody = strBody & strTemp & vbCrLf
Loop
Close #1
Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.getNameSpace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
EmailSend.To = strEmail
EmailSend.subject = "EMERGENCY"
'EmailSend.Attachments.Add strPath
EmailSend.Display
EmailSend.Body = strBody
Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing
Kill strPath
rstEmail.Close
Set rstEmail = Nothing
Dim strEmail As String
Dim rstEmail As DAO.Recordset
Dim EmailApp As Object
Dim NameSpace As Object
Dim EmailSend As Object
Set rstEmail = CurrentDb.OpenRecordset("Addresses")
Do Until rstEmail.EOF
strEmail = strEmail & rstEmail("EmailAddress") & ";"
rstEmail.MoveNext
Loop
If Right(strEmail, 1) = ";" Then
strEmail = Left(strEmail, Len(strEmail) - 1)
End If
strPath = DLookup("TextPath", "Filepath")
Kill strPath (this fixed my first problem but now if there is no file I get an error)
DoCmd.OutputTo acReport, "Email", acFormatRTF, strPath
Open strPath For Input As #1
Do Until EOF(1)
Line Input #1, strTemp
strBody = strBody & strTemp & vbCrLf
Loop
Close #1
Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.getNameSpace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)
EmailSend.To = strEmail
EmailSend.subject = "EMERGENCY"
'EmailSend.Attachments.Add strPath
EmailSend.Display
EmailSend.Body = strBody
Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing
Kill strPath
rstEmail.Close
Set rstEmail = Nothing