OL97: Programmatically-Created Attachment Loses Icon

Last reviewed: March 2, 1998
Article ID: Q172719
The information in this article applies to:
  • Microsoft Outlook 97

SYMPTOMS

Using Visual Basic Scripting Edition (VBScript) or Visual Basic for Applications code, you can attach one Microsoft Outlook 97 item to another. If you send a mail message with such an attachment, the person who receives the message may not be able to see the icon for the attachment. The attached item however, is intact and functions correctly.

CAUSE

This problem is a result of how you write the code for the item attachment. Using an object variable results in the problem described above.

RESOLUTION

When attaching the second item to the first, use the ActiveInspector.CurrentItem object to reference the attached item. For an example of how to resolve this problem, see the Corrected Code section below.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft Consult Line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

    http://www.microsoft.com/support/supportnet/refguide/default.asp

Corrected Code

If you repeat the steps below but follow the comment instructions to use:

    ItemToSend.Attachments.Add Application.ActiveInspector.CurrentItem, 4

      instead of

    ItemToSend.Attachments.Add Item, 4

your e-mail message will include the attachment icon.

Steps to Reproduce the Problem

  1. Create a new mail message.

  2. On the Tools menu, click Design Outlook Form.

  3. Drag to resize the message control, creating enough space for a CommandButton.

  4. Click the Control Toolbox button to view the Control Toolbox and drag a CommandButton to the form.

  5. On the Form menu, click View Code and type the following VBScript code in the Script Editor.

    NOTE: Be sure to change Line 4 in the code below to your e-mail name.

       Sub CommandButton1_Click()
       ' Saves the current mailitem in the Inbox
       Item.Save
       ' Create a new mail message
       Set ItemToSend = Application.CreateItem(0)
       ' Change below to your emailname to send message
       ItemToSend.To = "<enter your e-mail here>"
       ItemToSend.Subject = "test"
       ' The following line results in a blank icon for attachment.
       ' 4 is the olAttachmentType constant olByValue to create a link.
       ItemToSend.Attachments.Add Item, 4
       ' The following syntax will preserve the icon in the sent message
       ' if it's substituted for the line above.
       'ItemToSend.Attachments.Add Application.ActiveInspector.CurrentItem, 4
       ItemToSend.Send
       End Sub
    
    

  6. Close the VBScript editor.

  7. On the Tools menu, click Design Outlook Form to exit design mode.

  8. Click CommandButton1 to run the VBScript code. You should receive a new message in your Inbox that contains the blank attachment icon. If you single-click in the upper left portion of the message area, you will see the bounding box for the icon.

REFERENCES

For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q166368
   Title     : OL97: How to Get Help Programming with Outlook

   Article-ID: Q170783
   Title     : OL97: Q&A: Questions about Customizing or
               Programming Outlook


Additional query words: OutSol OutSol97
Keywords : kbcode
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.