April 21st, 2017, 10:41 AM
Join Date: Nov 2016
Time spent in forums: 32 m 39 sec
Reputation Power: 0
Email from Access 2010 using Outlook
Hi, I'm new to this part of access but what I am trying to accomplish if possible is the following:
I am having a problem with the code below. When I first put the code in it worked but only on the first record of the db. Today when I opened the db the code doesn't work at all. I don't get an error message the button that executes the code just sits with the outline around it in dashes and it doesn't do anything. When it was working when you hit the button it actually brought up the email and you had to hit send (which is what I want).
So why isn't the code currently working and why does it only work on the first record of the db.
And can I add criteria? Currently it is adding all of the task number names but I only want those added if the field ActiveCodes say "Request from Finance"
For example if the "ActiveWritingCode" field says "Request from Finance" I want the field "WriterTaskNumberName" in the body otherwise leave it blank.
Private Sub cmdEmail1_Click()
On Error GoTo cmdEMail_Click_Error
Dim OutApp As Object
Dim strEMail As String
Dim OutMail As Object
Dim strbody As String
strEMail = Me.EMail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Please add the following time codes to Oracle for Lilly Project 1000814. Thank you!" & vbCrLf _
& "" & vbCrLf & "INSTRUCTIONS:" & vbCrLf _
& "" & vbCrLf & "Make sure the Task Description starts with CO3. This is automatically added by entering CO3 in the Contract field on the form." & vbCrLf _
& "" & vbCrLf & "If you wish to keep track of your time code requests, CC: yourself on the e-mail and considering entering a compound name or other identifier in the subject line. Alternatively, save a copy of the spreadsheet with your time codes to your desktop." & vbCrLf _
& "" & vbCrLf & "WRITING TASK NUMBER NAME =" & [Forms]![frm_Regulatory]![WriterTaskNumberName] & vbCrLf _
& "" & vbCrLf & "ADD DRAFT TASK NUMBER NAME =" & [Forms]![frm_Regulatory]![AddDraftTaskNumberName] & vbCrLf _
& "" & vbCrLf & "EDIT TASK NUMBER NAME =" & [Forms]![frm_Regulatory]![EditTaskNumberName] & vbCrLf _
& "" & vbCrLf & "QUALITY REVIEW TASK NUMBER NAME =" & [Forms]![frm_Regulatory]![DataIntegrityQRTaskNumber] & vbCrLf _
& "" & vbCrLf & "Task Description =" & [Forms]![frm_Regulatory]![Text186] & vbCrLf
On Error Resume Next
If Me.ActiveWritingCode = "Request from Finance" Then
.To = strEMail
.CC = ""
.BCC = ""
.Subject = "Lilly US 1000814 Time Code Request"
.Body = strbody & vbNewLine & .Body
Set OutMail = Nothing
Set OutApp = Nothing
On Error GoTo 0
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdEMail1_Click of Sub Form_frm_Regulatory"