Change order or position of Lotus Note attachments using VBA
Posted on 2006-04-27
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
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
.Form = "Memo"
.Subject = Subject
.Body = BodyText
.SAVEMESSAGEONSEND = SaveIt
'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))
StartAttach = False
'Send the document
If intGotAttachment > 0 Then
.PostedDate = Now() 'Gets the mail to appear in the sent items folder
SendNotesMail = "Sent"
SendNotesMail = "Not Sent"
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
If StartAttach = True Then
intGotAttachment = intGotAttachment - 1
MsgBox "Error constructing Lotus Notes message"