Concatenating unread Outlook mails in a textbox
I have some code that grabs any unread emails from Outlook and displays them in a message box one at a time. However, I am trying to bring them into a multi line textbox.
Here is the code. If I unmark the 'TextBox1.Text = strMess I only get the last message but the MsgBox(strMess) gives me each message sequentially. What am I doing wrong?
VB Code:
Dim oApp As Outlook.Application = _
New Outlook.Application
Dim sClassComp = "IPM.Note"
Dim oNS As Outlook.NameSpace = _
oApp.GetNamespace("MAPI")
Dim oInbox As Outlook.MAPIFolder = _
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
oItems = oItems.Restrict("[Unread] = true")
Dim oMsg As Outlook.MailItem
Dim i As Integer
Dim strMess As String
For i = 1 To oItems.Count
If oItems.Item(i).MessageClass = sClassComp Then
oMsg = oItems.Item(i)
strMess = "Message #" & (i) & vbNewLine & _
(oMsg.SenderName) & vbNewLine & _
(oMsg.Subject) & vbNewLine & _
(oMsg.ReceivedTime) & vbNewLine & _
(oMsg.Body) & vbNewLine
'TextBox1.Text = strMess
MsgBox(strMess)
End If
Next
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing