I have a main form and a sub form. In the main form, I have a button that when clicked, prompts for the ID number and then emails that record from the subform. I would like to include the ID number in the email subject. However, because the ID resides on the subform, it is not recognized until after the email is already in my Outlook.
Here’s my code. As you can see, I had to comment out the part where it refers to the ME.ID. However, it is critical that the subject line has a reference to the ID.
Can anyone help me with this?
Thanks in advance.
Private Sub Command392_Click()
Dim db As DAO.Database
Dim stToAddresses As String, stCCAddresses As String
Dim rs As DAO.Recordset
Dim stDocName As String, stSubject As String, stMsgBody As String
Set db = CurrentDb
Set rs = db.OpenRecordset("District", dbOpenDynaset)
rs.MoveFirst
Do
If rs("District") = Me![District] Then
stToAddresses = rs("EmailAddress") & ": "
End If
rs.MoveNext
Loop Until rs.EOF
If Not IsNull(stToAddresses) Then
stToAddresses = Mid$(stToAddresses, 1, Len(stToAddresses) - 2)
'stCCAddresses = Mid$(stCCAddresses, 1, Len(stCCAddresses) - 2)
End If
rs.Close
db.Close
stDocName = "ResourceRequest"
'stSubject = "A New Resource Request - " & Me.ID & " - " & Me.CustName
stSubject = "A New Resource Request - " & Me.Client
stMsgBody = "Here is a request to fill. Thank you."
DoCmd.SendObject acReport, stDocName, acFormatSNP, stToAddresses, "john.doe@abc.com", , stSubject, stMsgBody
End Sub
Here’s my code. As you can see, I had to comment out the part where it refers to the ME.ID. However, it is critical that the subject line has a reference to the ID.
Can anyone help me with this?
Thanks in advance.
Private Sub Command392_Click()
Dim db As DAO.Database
Dim stToAddresses As String, stCCAddresses As String
Dim rs As DAO.Recordset
Dim stDocName As String, stSubject As String, stMsgBody As String
Set db = CurrentDb
Set rs = db.OpenRecordset("District", dbOpenDynaset)
rs.MoveFirst
Do
If rs("District") = Me![District] Then
stToAddresses = rs("EmailAddress") & ": "
End If
rs.MoveNext
Loop Until rs.EOF
If Not IsNull(stToAddresses) Then
stToAddresses = Mid$(stToAddresses, 1, Len(stToAddresses) - 2)
'stCCAddresses = Mid$(stCCAddresses, 1, Len(stCCAddresses) - 2)
End If
rs.Close
db.Close
stDocName = "ResourceRequest"
'stSubject = "A New Resource Request - " & Me.ID & " - " & Me.CustName
stSubject = "A New Resource Request - " & Me.Client
stMsgBody = "Here is a request to fill. Thank you."
DoCmd.SendObject acReport, stDocName, acFormatSNP, stToAddresses, "john.doe@abc.com", , stSubject, stMsgBody
End Sub