Solved

VB6, Outlook Object Model Read Inbox

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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