Hello
I have a main form (frmECNOE) that has one subform (subfrmECNDE). I am trying to send two different emails, based on whether ImpactYN field is true (This field is in the subform) First the code is sending to all, instead of testing for True value in field ImpactYN. Second when first record in the subform is ImpactYN = false, then all also receive and email, instead of only if ImpactYN = false getting the email.
I am placing both mainform and subform information in the body of email. I have the emails sending, just to everyone instead of delineating. I have tried to move a few statements around with no luck.
Any help is appreciated.
Raven
This didn't work either
I have a main form (frmECNOE) that has one subform (subfrmECNDE). I am trying to send two different emails, based on whether ImpactYN field is true (This field is in the subform) First the code is sending to all, instead of testing for True value in field ImpactYN. Second when first record in the subform is ImpactYN = false, then all also receive and email, instead of only if ImpactYN = false getting the email.
I am placing both mainform and subform information in the body of email. I have the emails sending, just to everyone instead of delineating. I have tried to move a few statements around with no luck.
Any help is appreciated.
Raven
Code:
Dim StrEmailName As String
Dim StrSubEmail As String
Dim Elook As New Outlook.Application
Dim EnewLook As Outlook.MailItem
Dim ADL As String
Dim rcst As DAO.Recordset
Dim SfrmEmail As String
Set EnewLook = Elook.CreateItem(olMailItem)
Set rcst = Me!subfrmECNDE.Form.RecordsetClone
SfrmEmail = Me!subfrmECNDE.Form!Combo33
ADL = vbNewLine & vbNewLine
If Me.DraftStatus.Value = -1 Then
With EnewLook
With rcst
If rcst!ImpactYN = True Then
StrSubEmail = "ECN " & Me.ecnnumber & " , Notify Only THIS IS A TEST!!! " & Me.[Customer Name]
If (rcst.RecordCount) Then
rcst.MoveFirst
StrEmailName = ""
Do Until rcst.EOF
StrEmailName = StrEmailName + ";" + Nz(rcst!DeptEmail, "")
rcst.MoveNext
Loop
Else
msg = "THERE ARE NO RECORDS WITH NOTIFY ONLY TO EMAIL"
Style = vbInformation + vbOKOnly
Title = "NO RECORDS TO SEND EMAILS TO"
MsgBox msg, Style, Title
End If
EnewLook.To = StrEmailName
EnewLook.Subject = StrSubEmail
EnewLook.Body = "On ECN " & Me.ecnnumber & " , Customer Name: " & Me.[Customer Name] & ADL & _
"Originator: " & Me.ORIGINATOR & " With an Impact Assessment of : " & Me.ECNIMPACT & ADL & _
"ISSUE: " & Me.ECNISSUE & ADL & _
"CHANGE: " & Me.ECNCHANGE
EnewLook.Send
rcst.Close
Set rcst = Nothing
Else
Dim AItemN As String
StrSubEmail = "ECN " & Me.ecnnumber & " , APPROVAL NEEDED - THIS IS A TEST! " & Me.[Customer Name]
ADL = vbNewLine & vbNewLine
'AItemN = Me!subfrmECNDE.Form!ActionItem
If (rcst.RecordCount) Then
rcst.MoveFirst
StrEmailName = ""
AItemN = ""
Do Until rcst.EOF
StrEmailName = StrEmailName + ";" + Nz(rcst!DeptEmail, "")
AItemN = AItem & ADL + Nz(rcst!ActionItem, "")
rcst.MoveNext
Loop
Else
msg = "THERE ARE NO RECORDS WITH NOTIFY ONLY TO EMAIL"
Style = vbInformation + vbOKOnly
Title = "NO RECORDS TO SEND EMAILS TO"
MsgBox msg, Style, Title
End If
EnewLook.To = StrEmailName
EnewLook.Subject = StrSubEmail
EnewLook.Body = "On ECN " & Me.ecnnumber & " , Customer Name: " & Me.[Customer Name] & ADL & _
"Originator: " & Me.ORIGINATOR & " With an Impact Assessment of : " & Me.ECNIMPACT & ADL & _
"ISSUE: " & Me.ECNISSUE & ADL & _
"CHANGE: " & Me.ECNCHANGE & ADL & _
"THE ACTION ITEMS REQUESTED IS AS FOLLOWS " & ADL & _
AItemN
EnewLook.Send
rcst.Close
Set rcst = Nothing
End If
End With
End With
End If
This didn't work either
Code:
Dim StrEmailName As String
Dim StrSubEmail As String
Dim Elook As New Outlook.Application
Dim EnewLook As Outlook.MailItem
Dim ADL As String
Dim rcst As DAO.Recordset
Dim SfrmEmail As String
Set EnewLook = Elook.CreateItem(olMailItem)
Set rcst = Me!subfrmECNDE.Form.RecordsetClone
SfrmEmail = Nz(Me!subfrmECNDE.Form!Combo33, "")
ADL = vbNewLine & vbNewLine
If Me.DraftStatus.Value = -1 Then
With EnewLook
With rcst
If rcst!ImpactYN = True Then
StrSubEmail = "ECN " & Me.ecnnumber & " , Notify Only THIS IS A TEST!!! " & Me.[Customer Name]
If (rcst.RecordCount) Then
rcst.MoveFirst
StrEmailName = ""
Do Until rcst.EOF
StrEmailName = StrEmailName + ";" + Nz(rcst!DeptEmail, "")
rcst.MoveNext
Loop
Else
msg = "THERE ARE NO RECORDS WITH NOTIFY ONLY TO EMAIL"
Style = vbInformation + vbOKOnly
Title = "NO RECORDS TO SEND EMAILS TO"
MsgBox msg, Style, Title
End If
EnewLook.To = StrEmailName
EnewLook.Subject = StrSubEmail
EnewLook.Body = "On ECN " & Me.ecnnumber & " , Customer Name: " & Me.[Customer Name] & ADL & _
"Originator: " & Me.ORIGINATOR & " With an Impact Assessment of : " & Me.ECNIMPACT & ADL & _
"ISSUE: " & Me.ECNISSUE & ADL & _
"CHANGE: " & Me.ECNCHANGE
EnewLook.Send
rcst.Close
Set rcst = Nothing
Else
Dim AItemN As String
StrSubEmail = "ECN " & Me.ecnnumber & " , APPROVAL NEEDED - THIS IS A TEST! " & Me.[Customer Name]
ADL = vbNewLine & vbNewLine
AItemN = rcst!ActionItem
If (rcst.RecordCount) Then
rcst.MoveFirst
StrEmailName = ""
AItemN = ""
Do Until rcst.EOF
StrEmailName = StrEmailName + ";" + Nz(rcst!DeptEmail, "")
AItemN = AItem & ADL + Nz(rcst!ActionItem, "")
rcst.MoveNext
Loop
Else
msg = "THERE ARE NO RECORDS WITH NOTIFY ONLY TO EMAIL"
Style = vbInformation + vbOKOnly
Title = "NO RECORDS TO SEND EMAILS TO"
MsgBox msg, Style, Title
End If
EnewLook.To = StrEmailName
EnewLook.Subject = StrSubEmail
EnewLook.Body = "On ECN " & Me.ecnnumber & " , Customer Name: " & Me.[Customer Name] & ADL & _
"Originator: " & Me.ORIGINATOR & " With an Impact Assessment of : " & Me.ECNIMPACT & ADL & _
"ISSUE: " & Me.ECNISSUE & ADL & _
"CHANGE: " & Me.ECNCHANGE & ADL & _
"THE ACTION ITEMS REQUESTED IS AS FOLLOWS " & ADL & _
AItemN
EnewLook.Send
rcst.Close
Set rcst = Nothing
End If
End With
End With
End If