mrussell71
IS-IT--Management
I have a form from which I want to create an XLS report and send the report to an email contained within the .xls report.
The action that I would like to happen "on click" is:
1. Run a query based upon a combo box selection and based upon a selecton of check boxes on the form. [mfg], [uncorrected_chk], and [corrected_chk]
2. Do a SendObject command, with the the command sending the query as a .xls file.
3. Open the email client (outlook) and place the [email_addr_to] field from the query in the To: box.
This is where I am having trouble. I cannot figure out how to populate the To: field with the [email_addr_to] field from the query.
Here is the code:
Private Sub e_mail_but_Click()
On Error GoTo Err_e_mail_but_Click
Dim strEmailTo As String
Dim strQryName As String
If uncorrected_chk = -1 And corrected_chk = 0 Then
strQryName = "qry_corr_info_by_mfg_corrected"
DoCmd.OpenQuery strQryName, acViewNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
ElseIf uncorrected_chk = 0 And corrected_chk = -1 Then
strQryName = "qry_corr_info_by_mfg_uncorrected"
DoCmd.OpenQuery strQryName, acNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
ElseIf uncorrected_chk = -1 And corrected_chk = -1 Then
strQryName = "qry_corr_info_by_mfg_both"
DoCmd.OpenQuery strQryName, acNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
End If
Exit_e_mail_but_Click:
Exit Sub
Err_e_mail_but_Click:
MsgBox Err.Description
Resume Exit_e_mail_but_Click
End Sub
I have tried a couple of different variations of the to: variant. But can't seem to get it to work. How should I instantiate the strEmailTo variable?
Any help would be appreciated.
The action that I would like to happen "on click" is:
1. Run a query based upon a combo box selection and based upon a selecton of check boxes on the form. [mfg], [uncorrected_chk], and [corrected_chk]
2. Do a SendObject command, with the the command sending the query as a .xls file.
3. Open the email client (outlook) and place the [email_addr_to] field from the query in the To: box.
This is where I am having trouble. I cannot figure out how to populate the To: field with the [email_addr_to] field from the query.
Here is the code:
Private Sub e_mail_but_Click()
On Error GoTo Err_e_mail_but_Click
Dim strEmailTo As String
Dim strQryName As String
If uncorrected_chk = -1 And corrected_chk = 0 Then
strQryName = "qry_corr_info_by_mfg_corrected"
DoCmd.OpenQuery strQryName, acViewNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
ElseIf uncorrected_chk = 0 And corrected_chk = -1 Then
strQryName = "qry_corr_info_by_mfg_uncorrected"
DoCmd.OpenQuery strQryName, acNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
ElseIf uncorrected_chk = -1 And corrected_chk = -1 Then
strQryName = "qry_corr_info_by_mfg_both"
DoCmd.OpenQuery strQryName, acNormal, acReadOnly
strEmailTo = "email_addr_to"
DoCmd.SendObject acSendQuery, strQryName, acFormatXLS, strEmailTo, , , "Catalog Correction Report", , -1
End If
Exit_e_mail_but_Click:
Exit Sub
Err_e_mail_but_Click:
MsgBox Err.Description
Resume Exit_e_mail_but_Click
End Sub
I have tried a couple of different variations of the to: variant. But can't seem to get it to work. How should I instantiate the strEmailTo variable?
Any help would be appreciated.