Email a snapshot

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I am tring to automate some reporting. I have a
query that pull the last 4 weeks of history by group,
region, distirct and store. I want to be able to export the
results for each district in an email. I want to have this
automated so all I have to do is run the sql and the emails
are created. Please help
Thanks
Mike Marquardt
 
Mike,

The snap shot file format is available only for reports,
so you have two choices.

1) You can send your query using another format, like
Excel.

2) You can create a report that is based on your query
and send the report instead of the query and then you can
use the snap shot file format.

Here's a simple example of a function that will send a
query or report as an email attachment:

Public Function fnSendQueryData(strEmail As String, strObj
As String, _
strDistrict As String)
On Error GoTo Err_fnSendQueryData

Dim strSubject As String
Dim strMsgTxt As String

strSubject = "Data Export For " & strDistrict

strMsgTxt = "Your message text goes here."

'To allow the user to edit the email, change
the "False" to "True" at the end
'of the below DoCmd statements.

'To send query: (snapshot format is not available for
queries)
DoCmd.SendObject acSendQuery, strObj, acFormatXLS,
strEmail, , , strSubject, strMsgTxt, False

'To send report:
'DoCmd.SendObject acSendReport, strObj, acFormatSNP,
strEmail, , , strSubject, strMsgTxt, False

Exit_fnSendQueryData:
Exit Function

Err_fnSendQueryData:
If Err.Number <> 2501 Then
MsgBox "Error #: " & vbTab & vbTab & Err.Number &
vbCrLf _
& "Description: " & vbTab & Err.Description
End If
Resume Exit_fnSendQueryData

End Function

You can execute the function using a line like this:

fnSendQueryData "(e-mail address removed)", "YourQueryOrReport
", "District 21"

You will also need to decide whether/how to dynamically
select the records to include in your query or report.
One method is to select parameters in a form and have your
query reference the controls on the form as filter
parameters. Likewise, the destination email address could
also be displayed in the form and passed to the function
call by referencing the text box containing the email
address. You could call the function from the click event
of a button on this form.
 
Back
Top