Hi
I've been trying to automate emails from access and cannot get them to send, now, through trying to resolve the issue I'm having problem with the loop any help would be appreciated with this as it is getting urgent and I'm running out of ideas
The code I have so far is:
[Public Function ULNEmail()
Dim MyDB As Database
Dim MyRS As Recordset
Dim TheAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("ULNNotificationEmailQry")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = MyRS![EmailAdd]
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo
.To = TheAddress
.Subject = "IMPORTANT INFORMATION REGARDING YOUR ULN"
.Body = "Hello" & _
vbCrLf & "Everybody who has enrolled at Eastleigh College or who has undertaken training with a partner of Eastleigh College receives a Unique Learner Number (ULN), issued by Eastleigh College. You may not have studied with us directly as we deliver a number of courses through Partner Agencies. Your ULN is:" & _
vbCrLf & [MyRS]![uln] & _
vbCrLf & _
vbCrLf & "Please follow the link http://www.eastleigh.ac.uk/student-s...ir-processing/ for information regarding what a ULN is and assurance that your personal data has been held securely."
.Importance = olImportanceHigh 'High importance
'SendUsingAccount is new in Office 2007
'Change Item(1)to the account number that you want to use
'.SendUsingAccount = objOutlookMsg.Session.Accounts.Item(1)
'.SentOnBehalfOfName = "ulns@eastleigh.ac.uk"
'Add the attachment to the e-mail message.
'Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.display
Else
objOutlookMsg.Send
End If
End With
Next
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Function]
Thank you