Solved

VB6, Outlook Object Model Read Inbox

Posted on 2013-11-17
2
742 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 63
TT Auto Dashboard 13 104
Outlook Macro to delete emails not meeting keywords 56 111
SQL Server 2012 to SQL Server 2016 24 54
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

737 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