Charlottew14
Registered User.
- Local time
- Today, 20:19
- Joined
- Oct 4, 2012
- Messages
- 32
Hello,
I'm a total novice when it comes to using code (and access generally!) and am having problems setting up my database to send emails, using access 2010.
I have a form which assigns tasks to different people, with a button to send an email alert when a new task has been assigned. The code I'm using to send the email is:
Dim olApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "name@company.com"
.Subject = "Task Assigned"
.HTMLBody = "Text"
.send
End With
MsgBox "Operation completed successfully"
which works fine, but i'm struggling to make the ".To = " line pick up an email address. Because they want to go to different people each time, I don't want to just have the one email address (as in the code above). I have a table with the email addresses - how can I ask it to pick up the email address depending on who the task has been assigned to?
Hope that makes sense.
Many thanks in advance!!
I'm a total novice when it comes to using code (and access generally!) and am having problems setting up my database to send emails, using access 2010.
I have a form which assigns tasks to different people, with a button to send an email alert when a new task has been assigned. The code I'm using to send the email is:
Dim olApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = "name@company.com"
.Subject = "Task Assigned"
.HTMLBody = "Text"
.send
End With
MsgBox "Operation completed successfully"
which works fine, but i'm struggling to make the ".To = " line pick up an email address. Because they want to go to different people each time, I don't want to just have the one email address (as in the code above). I have a table with the email addresses - how can I ask it to pick up the email address depending on who the task has been assigned to?
Hope that makes sense.
Many thanks in advance!!