Array out of bounds .display 2016

Treebys

Member
Outlook version
Email Account
Exchange Server
Hi, I hope someone can help. I have an Access 2003 database that has a Sub using VBA to create an email in the background, attach documents and then when ready display (or should). This has always worked fine until Office 2016. It seems to run the entire code ok until it hits .display as which point I get an 'Array Out of Bounds' error. The syntax appears to be correct and as I have said it worked on previous office version including 2015. The Sub creates an email . It's a lengthy bit of code but here is the section in question:

Set OLNS = objOutlook.GetNamespace("MAPI")
Set MailFolder = OLNS.GetDefaultFolder(olFolderDrafts)
objOutlook.ActiveWindow
Set MailFolder = OLNS.GetDefaultFolder(olFolderDrafts)
MailFolder.Display
Set objEmail = MailFolder.Items.Add

With objEmail
.To = strTo
.CC = strCc
.Subject = strSubject
.HTMLBody = strBody
objEmail.Attachments.Add strReportSummary
If blnDec = True Then
objEmail.Attachments.Add strDec
End If
objEmail.Attachments.Add CurrentProject.path & "\" & "KeyFacts.pdf"
objEmail.Attachments.Add CurrentProject.path & "\" & "Client Agreement.pdf"
.Display
End With

Any help/ideas appreciated. Thanks in advance.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
or.. does it work if you use objEmail.display? Also, if you copy/pasted it, delete that line and retype it. I had issues with some leading spaces one time - for whatever stupid reason, outlook didn't see them as spaces. deleting and retyping them fixed it.
 

Treebys

Member
Outlook version
Email Account
Exchange Server
Sorry I forgot which forum I posted this too. It's in an Access database and I was looking at my Access forum. So ....

Diane, I think you were right, thank you. I noticed something very odd. I opened the module and searched for '.Display' it cycled through 21 instances of it in the code but did not find/recognise the problem one (in sbEmail). I tried this several times and every time it missed the two instances of it in sbEmail.

I then tried highlighting '.Display' in sbEmail and then Ctrl+F again it found the 2 in sbEmail and the other 21. I then tried searching '.Display' again and this time at found all 23. It's as though it didn't recognise the ones in sbEmail but now suddenly does!?!

Anyway, it seems to be working now. Fingers-crossed!

Thanks again.
 
Top