Send Object using forms text box as body

S

SoggyCashew

Hello, I have a form named "AccidentEntry" and on this form is a subform
named "AccidentEntrysubform". I wanted to add a button at the bottom of my
"AccidentEntry" form to send an email using a text box on my subform
"AccidentEntrySubform" named "txtRootCause" as the Body. And have a subject
line say "New Accident Injury" and at the end of that it would have the ID
number from the text box "txtID" on my subfom as well. How could this be
done? Thanks!
 
S

SoggyCashew

I have come up with the code below and it works if the txtRootCause and the
txtID have data in it if not I get an Null error for the control being empty.
What could I add to the code to check and see if there is data in those
controls on my subform before runing the code and if null then gice a message
and set focus to one of them. Here is what I have so far.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sEmailList As String
Dim stSubject As String
Dim stText As String
Dim stRecordID As String
Dim RecDate As Variant
Dim stBody As String

RecDate = Me.AccidentEntrySubform.Form.txtDateOfOnsetIllness
stSubject = ":: New Help Desk Ticket ::"
stRecordID = Me.AccidentEntrySubform.Form.txtID
stBody = Me.AccidentEntrySubform.Form.txtRootCause

stText = "You have been assigned a new ticket." & Chr$(13) & Chr$(13) & _
"Record ID: " & stRecordID & Chr$(13) & _
"Received Date: " & RecDate & Chr$(13) & Chr$(13) & _
"Root Cause:" & stBody

Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT strEMail " & _
"FROM tblEmailAddresses;")

With rs
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
sEmailList = .Fields("strEMail")
.MoveNext
End If

If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
sEmailList = sEmailList & "; " & .Fields("strEMail")
.MoveNext
Loop
End If

.Close

End With

'Write the e-mail content for sending to assignee
DoCmd.SendObject , , acFormatTXT, sEmailList, , , stSubject, stText, -1

db.Close
Set rs = Nothing
Set db = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top