whanana
04-20-2007, 09:29 AM
I am trying to send an email from Access with a button, pulling certain information from the Access fields. I am lazy, I don?t want to have to interact with it all ? click the button and off it goes. I saw the KB entry on sending an email from excel, and I've tried to adapt it as best I can.
As of yet, I do not have a field in my database for an email address, but can easily add one and modify my forms, if needed. I want the macro to create and sent an email which does the following:
?add the lastname and firstname field data to the TO: for the current record. (we have an address book that should recognize the name as long as there is a comma in between.
?Add the Problem description field data to the Message body for the current record
?Add a Subject Line that says ?Your trouble ticket has been completed.? And append the Ticket # to the beginning or the end from the Ticket ID field.
The issue I am having is pulling data from the access database to insert into the email. What I have so far, is as follows:
Function SendEmail()
Dim OL As Object
Dim EmailItem As Object
Dim Wb As Workbook
Dim EmailAddress As String
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
EmailAddress = ?joe.dirt@mycompany.com"
With EmailItem
.Subject = "Your trouble Ticket has been completed"
.Body = "" 'Reference my access field
.To = EmailAddress
.Importance = olImportanceNormal
'.Attachments.Add 'I don't need an attachment
.Send
End With
Set OL = Nothing
Set EmailItem = Nothing
End Function
As of yet, I do not have a field in my database for an email address, but can easily add one and modify my forms, if needed. I want the macro to create and sent an email which does the following:
?add the lastname and firstname field data to the TO: for the current record. (we have an address book that should recognize the name as long as there is a comma in between.
?Add the Problem description field data to the Message body for the current record
?Add a Subject Line that says ?Your trouble ticket has been completed.? And append the Ticket # to the beginning or the end from the Ticket ID field.
The issue I am having is pulling data from the access database to insert into the email. What I have so far, is as follows:
Function SendEmail()
Dim OL As Object
Dim EmailItem As Object
Dim Wb As Workbook
Dim EmailAddress As String
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
EmailAddress = ?joe.dirt@mycompany.com"
With EmailItem
.Subject = "Your trouble Ticket has been completed"
.Body = "" 'Reference my access field
.To = EmailAddress
.Importance = olImportanceNormal
'.Attachments.Add 'I don't need an attachment
.Send
End With
Set OL = Nothing
Set EmailItem = Nothing
End Function