Change order or position of Lotus Note attachments using VBA

Posted on 2006-04-27
Last Modified: 2008-02-01
I'm using the following code to mail reports as attachments that have been printed as .pdf files. The reports are printed from the same database. This could be relevant if changing the name of the files or the order in which they are printed would help resolve my issue.

The problem is that the manager wants the attachments to appear in a specified order. How does Lotus Notes determine what order to display the attachments?

Lotus Notes consistently uses the same order.  I have tried changing:
1. The order of the reports in the Attachment variable (seems like the most obvious)
2. The alphanumeric order of the name of the reports
3. The creation date of the reports
4. The modified date of the reports
5. The size of the reports
6. The length of the name of the reports

What attribute does Lotus Notes use to determine the order of the attachments? It must be using some logic, as the results are always the same. But I can't tell what attribute of the file Lotus Notes is using to determine the order.

'Start a session to notes
   Set Session = CreateObject("Notes.NotesSession")
   'Get the sessions username and then calculate the mail file name
   'You may or may not need this as for MailDBname with some systems you
   'can pass an empty string
   MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
   'Open the mail database in notes
   Set Maildb = Session.GETDATABASE("", MailDbName)
   If Maildb.IsOpen = True Then
        'Already open for mail
   End If
   'Set up the new mail document
   Set MailDoc = Maildb.CREATEDOCUMENT
   With MailDoc
        .Form = "Memo"
        .Subject = Subject
        .Body = BodyText
        'Access 2000, Access XP
        'Allows for multiple SendTo,CopyTo,BlindCopy,Attachment
        .SendTo = Split(SendTo, ",")
        .CopyTo = Split(CC, ",")
        .BlindCopyTo = Split(BCC, ",")
        'Set up the embedded object and attachment and attach it
        StartAttach = True
        aryAttachment = Split(Attachment, "|")
        For intAttach = LBound(aryAttachment) To UBound(aryAttachment)
            intGotAttachment = intGotAttachment + 1
            Set AttachME = .createrichtextitem("Attachment" & CStr(intAttach))
            Set EmbedObj = AttachME.embedObject(1454, "", aryAttachment(intAttach), "Attachment" & CStr(intAttach))
        Next intAttach
        StartAttach = False

   'Send the document
        If intGotAttachment > 0 Then
            .PostedDate = Now() 'Gets the mail to appear in the sent items folder
            .Send False
            SendNotesMail = "Sent"
            SendNotesMail = "Not Sent"
        End If
   End With
   'Clean Up
   Set Maildb = Nothing
   Set MailDoc = Nothing
   Set AttachME = Nothing
   Set Session = Nothing
   Set EmbedObj = Nothing
   Exit Function
    If StartAttach = True Then
        intGotAttachment = intGotAttachment - 1
        Resume Next
        MsgBox "Error constructing Lotus Notes message"
        Resume 'Clean_Up
    End If
End Function
Question by:hollyjon
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    Some links:

    This pdf claims that the attachment order depends on the order that you select the files:

    This mentions the attachment order in regard to the "Rule Order"

    If none of these help, perhaps you should close this out and re-post it to the Lotus Topic Area:

    Good luck

    Author Comment


    The redbooks reference concerns the order of html file attachments in a fax. Unfortunately, the reason I'm asking is because the attachments do not "appear in the ... in the order they were added"

    The pertains to Exchange not Domino.

    Unfortunately I need to use Lotus Notes and was hoping someone else might have had a similar need to control the order.

    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    You say:
    <Lotus Notes consistently uses the same order>
    What is this order?

    What I mean is, if you attached a Word, Excel, Bitmap file, would they always be in the same order.
    (Word, Excel, Bitmap)
    Or is it alway some other order like:
    (Excel, Bitmap, Word)
    Or is it random?

    Suppose you attached a different set of Word, Excel, and Bitmap... Would it always be the same order as the first three?

    Author Comment

    Although that's an interesting question, it's not one that I have time to explore. "I'm using the following code to mail reports as attachments that have been printed as .pdf files." The problem that I need to solve is what order/logic is being applied when several files of the same type (and specifically .pdf files) are attached? How do I control that scenario?

    As to the question of "What is the order?", that's an excellent question, but one that has me stumped. My assumption was that the attachments would appear in the same order that they are added to the string variable "Attachment". But that is not the order in which they appear.

    Or maybe they do.... I'm going back and look at my strings again, perhaps I'm not adding them in the order that I think I am.  

    "I'll be back."


    Author Comment

    All right. Did some analysis on a sample and here's the results. The problem is that the "Order in email" needs to be the same as "Order added".  The "Alpha order" is close to the "Order added", because I chose to do that throught the code that creates the attachment string. I'm including it so that it is clear that the "Alpha order" is not influencing the "Order in email". The "Set" number references an email so all the files in set 1 are in the first email, etc.

    Set|order added|Order in email|Alpha order|Size (kb)      |File
    1      1      1      2      16      Rpt1b.pdf
    1      2      4      1      15      Rpt1a.pdf
    1      3      2      3      12      Rpt1c.pdf
    1      4      3      4      12      Rpt1d.pdf
    2      1      3      2      13      Rpt2b.pdf
    2      2      4      1      61      Rpt2a.pdf
    2      3      2      3      611      Rpt2c.pdf
    2      4      1      4      12      Rpt2d.pdf
    3      1      10      2      17      Rpt3b.pdf
    3      2      11      1      37      Rpt3a.pdf
    3      3      7      3      79      Rpt3c.pdf
    3      4      5      4      20      Rpt3d.pdf
    3      5      8      5      70      Rpt3e.pdf
    3      6      6      6      95      Rpt3f.pdf
    3      7      3      7      57      Rpt3g.pdf
    3      8      2      8      13      Rpt3h.pdf
    3      9      1      9      64      Rpt3i.pdf
    3      10      4      10      51      Rpt3j.pdf
    3      11      9      11      17      Rpt3k.pdf
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    Did any of the links provide any info?

    Author Comment

    No, but I have a partial solution.  We noticed that some were sent using the internal address and some with the external address. If the internal address is used then we retain the correct order (and the nice formatting).  The external address will result in some still undetermined order. So, if an internal address is available, those emails will contain the attachment in the correct order.

    However, for a mass mailing, I only have access to a list of external addresses. So, I would still like to hear if someone has a solution for controlling the order of attachments using an external address.

    LVL 74

    Accepted Solution

    hollyjon ,

    With the age of this question you probably won't get much more replys
    (Remember it took me about 10 days to work up the nerve to try)

    At about 21 days from the last post, this site will notify you that question needs to be closed.

    You can surely wait it out.

    But if you need a answer fairly quickly, I suugest you close this, and post the same question to the Lotus Notes/Domino Topic Area

    Take care!


    Author Comment

    Well, at least you gave it some attention.  And you're advice to try the question in the Lotus Notes section is probably the best advice. Thanks.  

    For anyone checking out this question, the main answer is to use internal addresses if at all possible.
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

    But you did not have to Accept my posts if they did not solve your problem.

    If you want to change this contact:

    I'll leave it up to you.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now