Solved

VB6, Outlook Object Model Read Inbox

Posted on 2013-11-17
2
724 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 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