Solved

VB6, Outlook Object Model Read Inbox

Posted on 2013-11-17
2
674 Views
Last Modified: 2013-11-20
Hi There,

We currently use the following code to read an Inbox to find a specific email based on the messageid.  Once found we extract information about the Outlook mail item like the subject, message text etc.  Pretty stock standard stuff.

            For iTemp = 1 To fol.Items.Count
                If fol.Items(iTemp).EntryID = sMessageId Then
                    'Ok, we have our first match.
                    sMessageId = fol.Items(iTemp).EntryID
                    'Bring back all the variables
                    sTo = fol.Items(iTemp).To
                    sCC = fol.Items(iTemp).CC
                    sBCC = fol.Items(iTemp).BCC
                    
                    sSubject = fol.Items(iTemp).subject

                    sText = fol.Items(iTemp).Body
                   sRecvDate = fol.Items(iTemp).ReceivedTime
                    sPriority = fol.Items(iTemp).Importance
                    sReadReceipt = IIf(fol.Items(iTemp).ReadReceiptRequested = False, 0, 1)
            
                    Set fol = Nothing
                    Set mainfolder = Nothing
            
                    ReadMessage = "SUCCESS"
                    GoTo EXITFUNCTION
                End If
            Next

Open in new window


As it is reading the properties of the email based on the number sequence it is found in the inbox - if a new email then arrives in the middle of this action - the wrong data then gets retrieved.  e.g  in the inbox I am reading email fol.Items(3).EntryID if another email then comes in, email 3 now becomes email 4 but the code is getting the properties of email 3 still which has just changed.

Is there a more robust way of doing this without the design flaw we have - seems a bit flaky if fol.items changes as emails come in ?

I recognise that changing the inbox view to sort ascending may resolve this but looking for a programmatical method because we cannot guarantee sort order.

Thanks in advance.
0
Comment
Question by:jcwiatr
2 Comments
 
LVL 5

Accepted Solution

by:
advfinance earned 500 total points
ID: 39656030
What about obtaining the item based on a certain index early on, then using this object throughout instead of always referring back to the collection?

For iTemp = 1 To fol.Items.Count

	Dim oMessage
	Set oMessage = fol.Items(iTemp)

	If oMessage.EntryID = sMessageId Then
		'Ok, we have our first match.
		sMessageId = oMessage.EntryID
		'Bring back all the variables
		sTo = oMessage.To
		sCC = oMessage.CC
		sBCC = oMessage.BCC
		
		sSubject = oMessage.subject

		sText = oMessage.Body
		sRecvDate = oMessage.ReceivedTime
		sPriority = oMessage.Importance
		sReadReceipt = IIf(oMessage.ReadReceiptRequested = False, 0, 1)

		Set fol = Nothing
		Set mainfolder = Nothing

		ReadMessage = "SUCCESS"
		GoTo EXITFUNCTION
	End If
Next

Open in new window


--
Chris
0
 
LVL 1

Author Comment

by:jcwiatr
ID: 39660638
Thanks Chris.  I will give it a try and post the results.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Use Multiple Forms 4 38
DIR issue 7 47
Vb.net 2008 2 49
Sorting multiple rows and columns, and count duplicates in Excel 2013 4 50
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

706 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

21 Experts available now in Live!

Get 1:1 Help Now