Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with code for sending automated email from Access

Status
Not open for further replies.

boblife42

Technical User
May 29, 2008
1
US
Hello,
Very new to programming in VBA and I have to rewrite or modify a the code below to send an automatic email if a check box is unchecked, or pop up the email message so that it can be modified. Right now the message pops up so that it can be modified.

Thank you for any help you can give,
Dean

'------------------------------------------------------------
' btn_ToEng_Click
'
'------------------------------------------------------------
Private Sub btn_ToEng_Click()
On Error GoTo btn_ToEng_Click_Err
Dim strAnswerman As String
If IsNull(Me.RequestDate) Or IsNull(Me.RequestedBy) Then
strAnswerman = MsgBox("Missing Data: to close without saving or sending an email, click YES.", vbYesNo)
If strAnswerman = vbYes Then
DoCmd.close acForm, "frm_ReportForm"
DoCmd.OpenForm "frm_Welcome", acNormal
End If



Else
'DoCmd.RunCommand acCmdRefresh
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim rsNotifyList As Recordset
Dim strNotifyList As String
Dim blnEditMsg As Boolean

Set rsNotifyList = CurrentDb.OpenRecordset("tbl_Notifications", dbOpenDynaset)
rsNotifyList.Filter = "[Department]='" & Me!EquipLookup.Form!location_dept.Value & "' and FailureNotify=True"
Set rsNotifyList = rsNotifyList.OpenRecordset()
strNotifyList = ""


Do Until rsNotifyList.EOF
strEmailAddress = DLookup("EmailAddress", "tbl_Requestors", "NickName='" & rsNotifyList!Nickname & "'")
strNotifyList = strNotifyList & strEmailAddress & ","
rsNotifyList.MoveNext
Loop
If strNotifyList <> "" Then
strNotifyList = Left(strNotifyList, Len(strNotifyList) - 1)
blnEditMsg = True 'False
Else
blnEditMsg = True
MsgBox "There are no email addresses on record for this department. Please provide a list of names to whom this notification should go and send to IT, then email to whom you think this message should go and add email addresses to notification.", vbCritical, "No Names Found"
DoCmd.SendObject acReport, "rpt_Request", "RichTextFormat(*.rtf)", "", "", "", "MISSING CONTACTS", "Please check maintenance database for a new request regarding the " & Me.equipment & ". This message was sent regarding department " & Me!EquipLookup.Form!location_dept.Value & ". Please correct list.", blnEditMsg
End If
rsNotifyList.close
DoCmd.SendObject acReport, "rpt_Request", "RichTextFormat(*.rtf)", strNotifyList, "", "", "Maintenance request: " & Me.equipment.Value, "Please check maintenance database for a new request regarding the " & Me.equipment & ".", blnEditMsg
' DoCmd.SendObject acReport, "rpt_Request", "RichTextFormat(*.rtf)", strNotifyList, "", "", "TEST MESSAGE: Department " & Me!EquipLookup.Form!location_dept.Value & " Supervisors", "This is a test beacon message from the equipment maintenance database. Please acknowledge by replying.", blnEditMsg
MsgBox "Thank you! Your request has been sent.", vbInformation, "Request Sent"
DoCmd.Minimize
DoCmd.close acForm, "frm_ReportForm"
DoCmd.SelectObject acForm, "frm_Welcome", False
End If
btn_ToEng_Click_Exit:
Exit Sub
btn_ToEng_Click_Err:
MsgBox Error$
Resume btn_ToEng_Click_Exit
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top