I have code that would scan a recordset and email a user the records that met a certain condition.
It worked fine until I added a lot more records to see how long it would take to scan. However after I did that, whether it had any effect on it or not, I now get an error message that states :
"Application-defined or object-defined error" when it gets to ".send"
I've added the Microsoft Outlook object library to my references so I'm not sure why it is doing this. Also When I type "mailoutlook." the "send" function is available, so I am confused.
Can anyone see anything wrong in my programming that might be creating this error? Thanks for any help
It worked fine until I added a lot more records to see how long it would take to scan. However after I did that, whether it had any effect on it or not, I now get an error message that states :
"Application-defined or object-defined error" when it gets to ".send"
I've added the Microsoft Outlook object library to my references so I'm not sure why it is doing this. Also When I type "mailoutlook." the "send" function is available, so I am confused.
Can anyone see anything wrong in my programming that might be creating this error? Thanks for any help
Code:
Dim myrecordset As Recordset
Dim database As database
Dim olapp As Outlook.Application
Dim mailoutlook As Outlook.MailItem
Dim msg As String
Set olapp = CreateObject("outlook.application")
Set mailoutlook = olapp.CreateItem(olMailItem)
Set database = CurrentDb
Set myrecordset = Me.Recordset
msg = ""
myrecordset.MoveFirst
Do While Not myrecordset.EOF
If Me.datedue - Date = 3 Then
msg = msg & "Sample number: " & myrecordset![sample] & vbCr & vbCr
End If
myrecordset.MoveNext
Loop
With mailoutlook
.Subject = "Late Samples"
.Body = "The following Samples are due in 3 days: " & vbCr & msg
.To = "user email address"
.Send
End With
Set olapp = Nothing
Set mailoutlook = Nothing
DoCmd.Quit
end sub