Hi, I am new here and new to VBA so any help will be greatly appreciatied. I have a form in my database (Access 2003) and a button to email a report based on the form, I am using a parameter in the query the report is based on to limit the report to a single record (i don't know if this is the best approach or not). I would also like to email a person based on an entry in the form and have the email address show up automatically along with the report attached when the email button is clicked. I have tried using docmd.sendobject but it will not let me specify the email address based on user entry in the form. I have tried a couple of code variations which i will add below. It should be noted that the email address field is not in the form but tied to it via a lookup (displays name of the person the email belongs too) of another table. If I add the email address to the form will it be easier to accomplish my goal? Let me know if you need any more information or clarification.
Here are the two of the codes i have tried:
1.
Dim rs As New ADODB.Recordset
rs.Open "MyQuery", CurrentProject.Connection
DoCmd.SendObject acSendReport, "ReportName", acFormatRTF, rs("Email"), , , "New Report Request", "Please find the attached report request, if you have any questions please contact the DS lead for request.", , True
rs.MoveNext
rs.Close
Set rs = Nothing
2.
Dim stDocName As String
Dim stToName As String
Dim stCCName As String
Dim stSubject As String
Dim stMessage As String
stDocName = "MyReport"
stToName = DLookup("", "MyQuery")
stCCName = "[EMAIL="email@email.com"]email@email.com"
stSubject = "New Report Request"
stMessage = "Attached is a new report request, if you have any questions contact the DS Lead."
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, stToName, stCCName, stSubject, stMessage, , True
Thanks in advance and sorry for it being so long.
Here are the two of the codes i have tried:
1.
Dim rs As New ADODB.Recordset
rs.Open "MyQuery", CurrentProject.Connection
DoCmd.SendObject acSendReport, "ReportName", acFormatRTF, rs("Email"), , , "New Report Request", "Please find the attached report request, if you have any questions please contact the DS lead for request.", , True
rs.MoveNext
rs.Close
Set rs = Nothing
2.
Dim stDocName As String
Dim stToName As String
Dim stCCName As String
Dim stSubject As String
Dim stMessage As String
stDocName = "MyReport"
stToName = DLookup("", "MyQuery")
stCCName = "[EMAIL="email@email.com"]email@email.com"
stSubject = "New Report Request"
stMessage = "Attached is a new report request, if you have any questions contact the DS Lead."
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, stToName, stCCName, stSubject, stMessage, , True
Thanks in advance and sorry for it being so long.