All Products  |   Support  |   Search  |   microsoft.com Guide  
 
  Home   |   Access   |   Excel   |   FrontPage   |   Outlook   |   PowerPoint   |   Word   |
October 6, 1997     Back to Microsoft Access Articles and Sample Apps  

Using Microsoft Access 97 or Access 2000 Report Snapshots and the Snapshot Viewer

Save trees while you electronically distribute your Microsoft Access reports

Download self-extracting Microsoft Word version of this page. (162K; expands to 245K)

Download Snapshot Viewer. (1.7M; expands to 2.8M)

Mark Gillis and David Shank, Microsoft Corporation
Updated July 1999

Contents

 

 
 

Overview picture of report snapshots and snapshot viewer

Distribute your Microsoft Access reports the modern way


 
 

You regularly print and distribute Microsoft® Access reports to users inside and even outside your organization. But you want an alternative to printing, photocopying, and mailing these reports, because you're spending way too much money. Besides, you'd much rather send them in e-mail or post them to a Web site for quick and easy access. Now that you think of it, you want your users to view these reports in full fidelity, including color, fonts, charts, and other embedded objects. While you're at it, throw in a user-friendly interface, and an exposed object model so you can program it just the way you want to. To top it off, you want all this without your users' needing a full or run-time Microsoft Access license to view and print Microsoft Access reports.

Well, that sounds like a tall order, but . . . no problem! The combination of report snapshots and Snapshot Viewer will fill the bill quite nicely.

What is a report snapshot and what is Snapshot Viewer?

Think of a report snapshot as a portable Microsoft Access report. A report snapshot file, with an .snp extension, contains a full-fidelity copy of each page of a report and preserves the report's two-dimensional layout, graphics, and other embedded objects.

Think of Snapshot Viewer as a portable Print Preview. It's a program you use to view, print, and electronically mail a report snapshot. Snapshot Viewer consists of a stand-alone executable program, a Snapshot Viewer control (Snapview.ocx), a Help file, and other related files. You can use the Snapshot Viewer control to view a report snapshot from Microsoft Internet Explorer version 3.0 or later, or any application that supports embedded objects, such as Microsoft Word, or ActiveX® controls, such as Microsoft Visual Basic® for Applications (VBA).

 

 
 

Picture of Snapshot Viewer with two report snapshot windows

Comparing information in two related reports


 
 

What you need

Microsoft Access 97 Service Release 1 or later, or Microsoft Access 2000

The ability to create a snapshot report was first delivered in Service Release 1 (SR-1) of Microsoft Access 97 and is also available in Microsoft Access 2000. To create a snapshot report, you need one of the following versions of Access or Office:

  • Microsoft Access 97 SR-1 or later
  • Microsoft Office 97 Professional Edition SR-1 or later
  • Microsoft Access 2000
  • Microsoft Office 2000 Professional
  • Microsoft Office 2000 Premium

If you are using Microsoft Access 97 and are not sure that you have SR-1 or later, click About Microsoft Access on the Help menu. If SR-1 or later is at the top of the About Microsoft Access dialog box, you're all set -- you can create report snapshots. If not, see information about downloading the current service release of Office 97 from the Office Update Web site.

Snapshot Viewer

Although you must have Microsoft Access 97 SR-1 or later to create report snapshots, you don't need a Microsoft Access license to view or print them, send them via e-mail, or publish them on the Web. All you need is Snapshot Viewer, which you can install from these sources:

  • The Access subfolder of the ValuPack folder on the Access 97 or Office 97 CD-ROM (SR-1 or SR-2). Double-click the self-extracting file, Snpvw80.exe.

    Note Snpvw80.exe installs Snapshot Viewer 8.0, which supports viewing and printing snapshot reports created with both Access 97 and Access 2000, but doesn't include the minor fixes made in Snapshot Viewer 9.0. The links below (or Access 2000 and Office 2000 setup) install Snapshot Viewer 9.0, which supports snapshot reports created with both Access 97 and Access 2000.
     

  • The Access Product Information section of the Microsoft Office Developer Forum Web site.
     
  • The link at the top of this page.
     
  • In Access 2000 and Office 2000, Snapshot Viewer 9.0 is automatically installed the first time you create or view a snapshot report.

Snapshot Viewer works with Microsoft Windows® 95 or later and Microsoft Windows NT® 3.51 or later. If you are using Microsoft Windows NT version 3.51, the Snapshot Viewer control (Snapview.ocx) requires Service Pack 5 or later.

Microsoft Outlook and Microsoft Internet Explorer 3.0

To send a report snapshot via e-mail, you'll also need an electronic mail client program that supports Messaging Application Programming Interface (MAPI), such as Microsoft Outlook. To display a report snapshot on the World Wide Web, you'll also need a Web browser that supports ActiveX controls, such as Microsoft Internet Explorer 3.0 or later.

Optional: Snapshot Viewer on your intranet

When you send a report snapshot via e-mail or distribute one on the Web, it's a good idea to always include a link to the software download page for Snapshot Viewer, in case your users don't have Snapshot Viewer installed. For better performance and user convenience, you may want to set up a local site on your corporate intranet for downloading the Snapshot Viewer. Here are the general steps:

  1. Download the Snapshot Viewer self-extracting file (Snpvw90.exe), but save it to disk (click Save it to disk in the Internet Explorer dialog box). You can also download it from the top of this Web page.
  2. Copy Snpvw90.exe to a public server on your corporate intranet.
  3. Provide a link to the file in the e-mail message. For example:

    http://Website/Downloads/Snpvw90.exe

Note These steps aren’t necessary for users of Access 2000 or Office 2000 viewing a snapshot report in e-mail, because the setup program in these versions automatically installs Snapshot Viewer the first time a user opens a snapshot report from e-mail or the file system.

Create a report snapshot

To create a report snapshot in Microsoft Access 97:

  1. On the Reports tab in the Database window, click the name of the report you want to export, and then on the File menu, click Save As/Export.

  2. In the Save As dialog box, click To An External File Or Database, and then click OK.

  3. In the Save As Type box, click Snapshot Format (*.snp).

  4. Click the arrow to the right of the Save In box and select the drive or folder to export to.

  5. In the File Name box, enter the file name.

  6. If you want, select Autostart to display the results in Snapshot Viewer, and then click Export.

To create a report snapshot in Microsoft Access 2000:

  1. In the Reports window in the Database window, click the name of the report you want to export, and then on the File menu, click Export.

  2. In the Save As Type box, click Snapshot Format (*.snp).

  3. Click the arrow to the right of the Save In box and select the drive or folder to export to.

  4. In the File Name box, enter the file name.

  5. If you want, select Autostart to display the results in Snapshot Viewer, and then click Save.

A report snapshot is based on the table or query behind the report, including any sorting or filtering defined by the current OrderBy or Filter property settings. If the report is based on a parameter query, Microsoft Access first prompts you for the parameter values, and then outputs the results.

Open and view a report snapshot in Snapshot Viewer

To open a report snapshot, just double-click the report snapshot in Windows Explorer.

Windows Explorer

Once your report snapshot is open, you can:

 

 
 

Picture of report snapshot in Snapshot Viewer


 
 

Click the navigation buttons to move between pages.

Type a page number to go to a specific page in the report.

Click the report snapshot to switch between the current magnification and Fit.

Click the Print button to print the report.

To view the report at different magnifications, right-click the report snapshot, point to Zoom, and then click Fit, Fill, or a magnification percentage. When you choose Fill, Snapshot Viewer adjusts the magnification of the page to fill the window. If the report is in portrait orientation, the report width or short side of the page fits the window; if the report is in landscape orientation, the height or short side of the page fits the window.

Now your users can easily and quickly view Microsoft Access reports online. And they can print only the report pages they need. The page numbers are in the box at the bottom of the Report Snapshot window. Selective printing is especially useful when your reports contain color and images, such as charts and pictures, which can take a long time to print.

Troubleshoot opening a report snapshot

  • Verify that the file has the correct extension (.snp) and is in report snapshot format. (In Windows Explorer, right-click the file and then click Properties; the Type should be Snapshot File.)

  • Make sure you have read permission for the file and its folder.

Send a report snapshot in electronic mail

Send a report snapshot as an embedded icon

You can send a report snapshot as an icon in e-mail by clicking Send on the File menu in Snapshot Viewer.

Picture of embedded icon in Outlook e-mail message with link

Snapshot Viewer opens a new e-mail message and embeds the report snapshot as an icon in the e-mail message.

Include a link to the Snapshot Viewer download page just in case a user doesn't have it.

 

You can also send a report snapshot via e-mail as an icon by selecting a report in the database window, and then clicking Send on the File menu in Microsoft Access 97, or by clicking Send To on the File menu in Microsoft Access 2000. Even better, create a macro that uses the SendObject action to automate the process. For example:

Send Snapshot macro

Action

Argument

Value

SendObject

Object Type

Report

 

Object Name

Summary of Sales by Quarter

 

Output Format

Snapshot Format

 

To

Northwind Traders employees; Northwind Traders shareholders

 

Cc

 

 

Bcc

 

 

Subject

Quarterly Sales report

 

Message Text

 

 

Edit Message

No

Note The previous example uses the Northwind Traders sample database of Microsoft Access. If this database is not installed on your computer, search Microsoft Access Help for "Northwind database."

Depending on how your electronic mail program was set up, you may not be able to send a report snapshot programmatically if the electronic mail program requires you to log on and enter information. For example, Microsoft Outlook can be installed to prompt you for a user profile when you log on. Therefore, you may need to modify the installation of your electronic mail program.

Send a report snapshot as an embedded object

You can embed a report snapshot as an object in an e-mail message by using an electronic mail program that supports embedding objects. For example, in Microsoft Outlook click Object on the Insert menu; click Create from File, and then type the report snapshot file name in the File box, or click Browse to search for the file. Your message must be composed using the Microsoft Outlook Rich Text format to support embedded objects.

When your e-mail recipients read the e-mail message, they can double-click the embedded snapshot report to activate Snapshot Viewer in place and read the report.

 

 
 

Picture of report snapshot in presentation mode


 
 

Notes

  • You can only embed a report snapshot as an icon, not as an embedded object, from Microsoft Access or Snapshot Viewer.

  • Embedding a report snapshot file as an object produces a larger e-mail message in Windows 95 than it does in Windows NT, and may prevent you from sending the e-mail message (because of the size limitations of your electronic mail program). The size difference is caused by differences in the way the two operating systems support Windows metafiles. See the Snapshot Viewer Readme.txt file (in the C:\Program Files\Snapshot Viewer folder) for some tips to reduce the size of the e-mail message.

Distribute report snapshots regularly on the World Wide Web

If you regularly distribute lots of reports, such as weekly stock-level reminders, monthly sales reports, or quarterly financial statements, you may want to use the World Wide Web as a sort of "report clearinghouse."

Create report snapshots automatically

To automate the creation of your reports, create a macro in Microsoft Access 97 or 2000 that uses the OutputTo action (one for each report you want to output) to export each report as a report snapshot to the Web server where you publish your reports. For example:

Create Snapshot macro

Action

Argument

Value

OutputTo

Object Type

Report

 

Object Name

Catalog

 

Output Format

Snapshot Format

 

Output File

\\Website\Inetpub\wwwroot\
Webreports\Catalog.snp *

 

Auto Start

No

* Output directly to the folder on the World Wide Web server.

Publish your report snapshots

Once you have created your report snapshots, there are two ways you can publish them on the World Wide Web:

1. Create a link to each report snapshot. Use a HyperText Markup Language (HTML) Anchor tag on a Web page. For example:

 

 
 
<A HREF="http://Website/Webreports/catalog.snp">Catalog report</A>

 

When your users click the link, Microsoft Internet Explorer activates the report snapshot and Snapshot Viewer in place in the Microsoft Internet Explorer window. Other browsers open the report snapshot in a separate Snapshot Viewer window. In either case, Snapshot Viewer must be installed on the same machine as the browser. Therefore, it's a good idea to provide an additional link on the Web page to a software download page for Snapshot Viewer, in case your users don't have Snapshot Viewer installed.

 

 
 

Picture of Snapshot Report on the Web - in-place activation


 
 

Remind your users to use the Snapshot Viewer Print button to print all the pages of the report snapshot, and not the Microsoft Internet Explorer Print command, which prints only the current Web page.

2. Embed the Snapshot Viewer control on the Web page. Use the HTML Object tag. For example:

 

 
 
<OBJECT ID="SnapshotViewer" WIDTH=640 HEIGHT=480
    CLASSID="CLSID:F0E42D60-368C-11D0-AD81-00A0C90DC8D9">
        <PARAM NAME="_ExtentX" VALUE="16722">
        <PARAM NAME="_ExtentY" VALUE="11774">
        <PARAM NAME="_Version" VALUE="65536">
        <PARAM NAME="SnapshotPath"
    VALUE="http://Website/Webreports/catalog.snp">
        <PARAM NAME="Zoom" VALUE="0">
        <PARAM NAME="AllowContextMenu" VALUE="-1">
        <PARAM NAME="ShowNavigationButtons" VALUE="-1">
        </OBJECT>

 

You can embed the Snapshot Viewer control by using a Web page editor such as Microsoft FrontPage®. However, you can only use this method if you and your users are running a browser that supports ActiveX controls, such as Microsoft Internet Explorer version 3.0 or later. To automatically download and install the Snapshot Viewer control for users who don’t have Snapshot Viewer, you can copy the Snapview.ocx file to a Web server on your corporate intranet and use the Codebase attribute of the HTML Object tag. For example:

 

 
 
<OBJECT ID="SnapshotViewer" WIDTH=640 HEIGHT=480
    CLASSID="CLSID:F0E42D60-368C-11D0-AD81-00A0C90DC8D9"
CODEBASE="http://Website/LocalControls/Snapview.ocx">

 

Schedule the creation and publication of your report snapshots

To regularly schedule the whole process, you can use a scheduling program, such as Windows NT AT, Microsoft Plus! System Agent, or Windows 98 Task Scheduler. For example, create the following batch file to run your Create Snapshot macro:

Batch file: Webpost.bat

 

 
PATH = "C:\Program Files\Microsoft Office\Office\;C:\Windows\Command"
REM The next 2 lines must be 1 line in the batch file to execute.
START /WAIT Msaccess.exe "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb" /x "Create Snapshot"
EXIT

 

And then use System Agent (SysAgent.exe) to run the batch file for you on a regular schedule.

Picture of System Agent window

Troubleshoot opening report snapshots from a Web page

If you are attempting to open the report snapshot from a Web page, you may experience a connection or time-out problem while the report snapshot is being downloaded. Redisplay the Web page, or restart your Web browser to see if that fixes the problem.

Do it your way: two sample applications

Let's say your company keeps customer and sales data in a Microsoft Access database at company headquarters. In the past, when an employee in the home office needed to see a report, you had to print the reports and send them through inter-office mail. Or when one of your traveling salespeople needed a report, they telephoned or sent an e-mail request and you faxed back the report. But now you want to take full advantage of report snapshots and the Snapshot Viewer. The following sample applications show how you can customize the viewing and distribution of report snapshots to fit the unique needs of your company.

The SnapshotBrowser sample application: viewing and printing reports on a network server

(To view the complete source code for this application, click here.)

You now want to make all reports available online to employees in the home office. Although no employee has direct access to the company's Microsoft Access database, there is a shared network server available that employees can use to store and exchange files. So, you create a folder named Reports on that network server and a subfolder for each month of the year. Then for every report that is created during the month, you save it to the corresponding subfolder as a report snapshot. Finally, you instruct your users to run the SnapshotBrowser application to view and print any report snapshot for any month of the year in the Reports folder.

The SnapshotBrowser sample application

Picture of sample application running/viewing report snapshots

SnapshotBrowser, a Microsoft Visual Basic 5.0 application, uses a single form that contains a Snapshot Viewer ActiveX control (Snapview.ocx) and a TreeView control. The TreeView control is used to browse the snapshot files stored in the Reports folder on your network server.

When the application starts, it loads the TreeView control with the names of the months representing the subfolders that contain the snapshot reports. The application uses class modules to represent the month subfolders and each report contained in a month subfolder. A custom function fills a Months collection object with a Month object for each month subfolder. The procedure then fills a Reports collection with a Report object for each snapshot file found in a month subfolder. (These are custom objects and collections and have no relation to Microsoft Access built-in objects and collections.) Following is the code used to fill the Months collection with Month objects:

 

 
 
Dim strFolderName As String
   Dim objMonth As New Month
    ' gstrFolderPath must contain the UNC path 
    ' to the network server where your snapshot
    ' reports are stored.
    gstrFolderPath = ""
    ' Find the first month subfolder under the Reports 
    ' folder.
    strFolderName = Dir(gstrFolderPath & "*", vbDirectory)
    ' For each month subfolder found, add it to the Months 
    ' collection.
    If Len(strFolderName) > 0 Then
        Do Until strFolderName = ""
              If strFolderName <> "." _
                      And strFolderName <> ".." Then
                  Set objMonth = colMonths.Add(strFolderName, _
                      strFolderName)
              End If
           strFolderName = Dir
        Loop
    End If

 

Once the Months collection is filled with Month objects, the FillReports function is called to fill the Reports collection for each Month object with Report objects for each report found.

 

 
 
Sub FillReports()
    ' This procedure adds a Reports collection containing
    ' all snapshot files contained in each month subfolder.
    Dim strFileName As String
    Dim objMonth As Month
    Dim objRpt As New Report
    For Each objMonth In colMonths
        Set colRpts = New Reports
        strFileName = Dir(gstrFolderPath & _
        objMonth.Name & "\*.snp", vbNormal)
    ' For each snapshot file contained within the Month 
    ' subfolder, add the snapshot to the Reports collection.
    If Len(strFileName) > 0 Then
            Do Until strFileName = ""
                With objRpt
                     .Name = strFileName
                     Set .Parent = objMonth
                End With
                ' Add this snapshot file to the Reports
                ' collection associated with this Month object.
                colRpts.Add objRpt.Name, objRpt.Name
                strFileName = Dir
             Loop
        End If
        Set objMonth.Reports = colRpts
        Set colRpts = Nothing
    Next objMonth
End Sub

 
Note In the preceding code samples, the variables colMonths and colReports are Public variables declared in a standard module.

When a user selects a month from the TreeView control, all the report snapshot files contained in that subfolder are displayed in the left pane of the application's main form. When a user selects a report snapshot from the TreeView control, the report is displayed using the Snapshot Viewer control. You use the SnapshotPath property to specify which snapshot file to display in the Snapshot Viewer ActiveX control. The SnapshotBrowser sample application sets this property using the following code:

 

 
 
SnapshotViewer1.SnapshotPath = gstrFolderPath & _
       Node.Parent.Text & "\" & Node.Text

 

The variable gstrFolderPath contains the UNC path to the main Reports folder. Node.Parent.Text contains the name of the month subfolder and contains Node.Text, the report snapshot file name.

Note If you want to use this sample application, you must make sure you set up the Reports and Months folders exactly as they are set up in this example. In addition, you must change the variable gstrFolderPath (found in the Declarations section of Module1) to the UNC path to the Reports folder on your network server.

The Snapshot Viewer control exposes a SnapshotViewer object that contains properties, methods, and events you can use to programmatically manipulate all aspects of the control. For example, the following subroutine shows how the Print Report button calls the Snapshot Viewer control's PrintSnapshot method to print the report currently displayed in the control.

 

 
 
Private Sub cmdPrint_Click()
    Const conNoCurrentReport as Integer = 2502
    On Error Resume Next
    SnapshotViewer1.PrintSnapshot True
    If Err = conNoCurrentReport Then
        MsgBox "Please select a report to print."
    End If
End Sub

 

For more information on programming the Snapshot Viewer control, view the Help file that comes with the Snapshot Viewer. The Help file provides language reference topics for all of the Snapshot Viewer control's properties, methods, and events.

The AutomatedMailer sample application: round the clock remote access to multiple report snapshots via e-mail

(To see the full source code for this application, click here.)

Next, you decide to create an automated report snapshot mailer application. Your remote salespeople can now request reports by sending you e-mail and automatically receive the requested report snapshots embedded in the e-mail reply message. The AutomatedMailer sample application automates these e-mail reply messages, providing the requested snapshot files automatically. To get an automated e-mail reply containing snapshot files, the user creates an e-mail message addressed to you with the word "MailReport" anywhere in the message subject line. In addition, in the body of the message the user specifies the names of the reports requested as a comma-delimited list: "Reports: reportname1, reportname2, reportnameN" (for example, "Reports: Stock-level, Quarterly Statement, Top Customers"), and the name of the month subfolder where they're stored: "Month: monthname" (for example, "Month: September").

Sample e-mail message requesting snapshot reports

Note The code the parses the body of the e-mail message to determine the names of the requested month and reports will ignore any other text in the message.

You must complete the following five steps for this sample application to work correctly on your machine:

  1. Store your snapshot files in the directory structure described in the previous section, "The SnapshotBrowser sample application: viewing and printing reports on a network server."

  2. Create an folder named MailReport.

  3. Create an Outlook rule that places report request e-mail into the MailReport folder. You create rules in Outlook by using the Rules Wizard or the Inbox Assistant (Tools menu).

    Rules Wizard

    The Rules Wizard displays the rule created to send e-mail to the MailReport folder.

  4. Specify the UNC path to the network server containing the Reports folder. You enter this information in the Text property of the txtRptDirectoryPath text box.

    Note The AutomatedMailer sample application also uses a form that allows you to specify or change this path setting while the program is running.

  5. Set a reference to the Microsoft Outlook 8.0 Object Library.

The sample application, a Visual Basic 5.0 program, will automatically reply to any e-mail message asking for reports (when submitted in the proper format). The sample works by calling code at regular intervals to check for new e-mail in the MailReport folder. If the application finds an unread message in the MailReport folder, it parses the text in the body of the message to determine the specified month and reports requested. The code then creates a reply message, lists the reports requested, indicates whether each file was found in the specified month subfolder, attaches the requested report files to the e-mail message, and sends the reply e-mail back to the person requesting the reports.

The AutomatedMailer application has one form that contains a Timer control. You use the Timer control's Interval property to specify (in milliseconds) how often to check for new e-mail in the MailReport folder. The sample also shows how you can change this Interval property while the application is running. The application uses the following custom function to check for new e-mail:

 

 
 
Private Function CheckForMail(objColl As Collection) As Boolean
    ' This procedure looks in the MailReport folder
    ' to determine if there are unread MailItem objects.
    ' Each unread MailItem object is added to the global objColl 
    ' collection for later processing.
    Dim objOutlook As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Object
    Dim objItems As Outlook.Items
    Dim obj As Object
    ' Initialize Outlook object variables.
    Set objOutlook = New Outlook.Application
    Set objNS = objOutlook.GetNamespace("MAPI")
    For Each objFolder In objNS.Folders
        If InStr(objFolder.Name, "Mail") > 0 Then
            ' Find all unread MailItem objects in the
            ' "MailReport" folder.
            Set objItems = objFolder.Folders("MailReport").Items. _
                Restrict("[UnRead] = True")
            If objItems.Count > 0 Then
            For Each obj In objItems
                objColl.Add obj
                Next obj
                CheckForMail = True
            Else
                CheckForMail = False
                Exit Function
            End If
        End If
    Next objFolder
End Function

 

If there is an unread e-mail message in the MailReport folder, then the ReplyToMail custom function is used to create and send the reply message. The ReplyToMail function uses the MailItem object's Reply method to create the reply. It then parses the body of the original e-mail message to determine the month and reports names specified. This information is used to attach the snapshot reports to the message reply. To determine the report names requested, the code parses the original message body, extracts each report name, and places the names in an array using the code:

 

 
 
arrRequestedRpts = ParseMail(strBody)

 

The ParseMail function uses the following code to enter each report name into an array and then return that array to the variable arrRequestedRpts in the ReplyToMail procedure:

 

 
 
Function ParseMail(strBody As String) As Variant
    ' This procedure parses the body of the e-mail message to get
    ' the names of the requested report snapshot files.
    Dim strTemp As String
    Dim strTempRpt As String
    Dim intCntr As Integer
    Dim arrRptNames() As String
    On Error Resume Next
    ' Find the report names in the message body.
    If InStr(strBody, "Reports:") <> 0 Then
       strTemp = Mid(strBody, InStr(strBody, "Reports: ") + 8)
    Else
        ParseMail = "Incorrect report request format detected."
        Exit Function
    End If
    Do
        ' Increase array size to handle each 
        ' found report - cumulative.
        ReDim Preserve arrRptNames(intCntr)
        strTempRpt = strTemp
        ' Determine if more than one report has been requested.
        If InStr(strTempRpt, ",") > 0 Then
            ' Add the report name to the array.
            arrRptNames(intCntr) = Trim(Left(strTempRpt, _
                InStr(strTempRpt,",") - 1))
        Else
            arrRptNames(intCntr) = Trim(strTempRpt)
            ParseMail = arrRptNames()
            Exit Function
        End If
        intCntr = intCntr + 1
        strTemp = Mid(strTemp, InStr(strTemp, ",") + 1)
    Loop Until InStr(strTemp, ",") = 0
    ReDim Preserve arrRptNames(intCntr)
    ' Add last listed report name to array.
    arrRptNames(intCntr) = Trim(Left(strTemp, _
        InStr(strTemp, ".snp") + 3))
    ParseMail = arrRptNames()
End Function

 

Once the array of report names is filled, the following code attaches each report to the e-mail message reply. Note how it modifies the e-mail message if an error occurs trying to locate the snapshot file in the specified file folder.

 

 
 
' Attach each requested report to the reply message.
    For Each strItem In arrRequestedRpts
        .Attachments.Add conRptPath & strMonth & "\" & strItem
        If Err = conFileNotfoundError Then
            ' Text to indicate invalid report name.
            .Body = .Body & vbCrLf & strItem & _
                " (ERROR: File Not Found)"
            Err = 0
        ElseIf Err = conInvalidFilePath Then
            ' Text to indicate invalid file path error.
            .Body = .Body & vbCrLf & strItem _
                & " (ERROR: Invalid File Path Submitted)"
            Err = 0
       ElseIf Err = 0 Then
           ' Add attached file name to message body.
           .Body = .Body & vbCrLf & strItem
        End If
        DoEvents
    Next strItem

 

After the reply has been created, it is sent using the MailItem's Send method and then the original e-mail message is deleted from the MailReport folder using the MailItem's Delete method.

Summary

The AutomatedMailer sample application illustrates how to automate e-mail replies to requests for report snapshots by following these steps:

  • Create a rule in Microsoft Outlook to direct any e-mail with "MailReport" in the Subject line to an Outlook subfolder named MailReport.

  • Create VBA code to:

    • Parse the body of the e-mail message to get the month specified.

    • Parse the body of the e-mail message to get the list of report names requested.

    • Use the Outlook MailItem's Reply method to create a reply to the e-mail request.

    • Embed a report snapshot file in the reply message.

    • If an invalid file name is detected, insert an error message indicating the report could not be found.

    • Send the e-mail back to the person who requested it.
 

 
 
 

Tell us about this article
-Very worth reading
-Worth reading
-Not worth reading
-Too detailed
-Just right
-Not detailed enough
-Too technical
-Just right
-Not technical enough




 
 
 

Comments? Suggestions? Write us at MSDN@microsoft.com.

 
  © 2000 Microsoft Corporation. All rights reserved. Terms of Use.
Last Updated: August 24, 2000

 
  Best experienced with
Microsoft Internet Explorer
Click here to start.