C
Cody MacLeod
Guest
I am reading unread emails from my Outlook inbox and displaying them in a datagridview.
There is a RichTextBox that should populate the body of the email each time a new row is selected.
DataGridView selection mode is currently set to EntireRow.
Currently, all data is being populated. However, the RichTextBox is only displaying the body of the LAST row. When I switch rows, it remains as the data populated in the last field (my For Loop is reaching the end and over-writing the rest.)
I am aware that one way to accomplish this is by creating an array, and calling from the index of the array. However I am unsure how exactly to write this.
Somewhat new to Visual Basic. Any assistance is appreciated.
I have the following code:
' Create Outlook application.
Dim OutlookApplication As Outlook.Application = New Outlook.Application
' String used for comparison with mail item.
Dim sClassComp = "IPM.Note"
'Get Message Collection
Dim OutlookNameSpace = OutlookApplication.GetNamespace("MAPI").Folders("Inbox").Folders("Inbox").Folders("Alerts")
Dim InboxItems As Outlook.Items = OutlookNameSpace.Items
'Total Inbox Emails
'RichTextBox1.AppendText("Total Alerts: " & inboxItems.Count)
' Get unread e-mail messages.
Dim UnreadInboxItems As Outlook.Items = InboxItems.Restrict("[Unread] = true")
' Loop each unread message.
Dim UnreadInboxMessage As Outlook.MailItem
Dim i As Integer
For i = 1 To UnreadInboxItems.Count
'Test to make sure item is a mail item and not a meeting request.
If UnreadInboxItems.Item(i).MessageClass = sClassComp Then
UnreadInboxMessage = UnreadInboxItems.Item(i)
Dim UnreadMessageNumber = i
Dim UnreadMessageSubject As String = UnreadInboxMessage.Subject
Dim UnreadMessageBody As String = UnreadInboxMessage.Body
RichTextBox1.Text = UnreadMessageSubject & UnreadMessageBody
End If
Next
Continue reading...
There is a RichTextBox that should populate the body of the email each time a new row is selected.
DataGridView selection mode is currently set to EntireRow.
Currently, all data is being populated. However, the RichTextBox is only displaying the body of the LAST row. When I switch rows, it remains as the data populated in the last field (my For Loop is reaching the end and over-writing the rest.)
I am aware that one way to accomplish this is by creating an array, and calling from the index of the array. However I am unsure how exactly to write this.
Somewhat new to Visual Basic. Any assistance is appreciated.
I have the following code:
' Create Outlook application.
Dim OutlookApplication As Outlook.Application = New Outlook.Application
' String used for comparison with mail item.
Dim sClassComp = "IPM.Note"
'Get Message Collection
Dim OutlookNameSpace = OutlookApplication.GetNamespace("MAPI").Folders("Inbox").Folders("Inbox").Folders("Alerts")
Dim InboxItems As Outlook.Items = OutlookNameSpace.Items
'Total Inbox Emails
'RichTextBox1.AppendText("Total Alerts: " & inboxItems.Count)
' Get unread e-mail messages.
Dim UnreadInboxItems As Outlook.Items = InboxItems.Restrict("[Unread] = true")
' Loop each unread message.
Dim UnreadInboxMessage As Outlook.MailItem
Dim i As Integer
For i = 1 To UnreadInboxItems.Count
'Test to make sure item is a mail item and not a meeting request.
If UnreadInboxItems.Item(i).MessageClass = sClassComp Then
UnreadInboxMessage = UnreadInboxItems.Item(i)
Dim UnreadMessageNumber = i
Dim UnreadMessageSubject As String = UnreadInboxMessage.Subject
Dim UnreadMessageBody As String = UnreadInboxMessage.Body
RichTextBox1.Text = UnreadMessageSubject & UnreadMessageBody
End If
Next
Continue reading...