Nikitas10
09-29-2010, 08:13 AM
Hello,
I'm trying to use a 'Items.Restrict' command to isolate mail items to create a report. I'm trying to run that command on a selected mail of a random mail folder, not the default inbox. Please, can you help?
My code is
Dim logit As MailItem
Dim gUserName, sconv, sfrom, ssub, sFolder As String
Dim icounter As Integer
Dim itms As Outlook.Items
Dim itm As Outlook.MailItem
Dim fld As Outlook.MAPIFolder
If Application.ActiveExplorer.Selection.Count > 1 Then
MsgBox ("Only a single email can be logged at any time.")
Exit Sub
End If
Set logit = Application.ActiveExplorer.Selection.Item(1)
If logit.Class <> olMail Then
MsgBox ("Only mail items can be logged.")
Exit Sub
End If
gUserName = TheCurrentUser()
sFolder = logit.Parent.Name
sconv = logit.ConversationIndex
sfrom = logit.SenderName
ssub = logit.Subject
Set fld = Application.Session.GetDefaultFolder(olFolderInbox)
'This targets my Inbox, I have to find how to use the folder called sFolder from the selected item !!!!! I need to somehow define the fld correctly
strFind = "[ConversationTopic]=" & Chr(34) & logit.ConversationTopic & Chr(34)
Set itms = fld.Items.Restrict(strFind)
icounter = 0
For Each itm In itms
'I'll write the code here.
icounter = icounter + 1
Next
Any help is much appreciated. Thanks
I'm trying to use a 'Items.Restrict' command to isolate mail items to create a report. I'm trying to run that command on a selected mail of a random mail folder, not the default inbox. Please, can you help?
My code is
Dim logit As MailItem
Dim gUserName, sconv, sfrom, ssub, sFolder As String
Dim icounter As Integer
Dim itms As Outlook.Items
Dim itm As Outlook.MailItem
Dim fld As Outlook.MAPIFolder
If Application.ActiveExplorer.Selection.Count > 1 Then
MsgBox ("Only a single email can be logged at any time.")
Exit Sub
End If
Set logit = Application.ActiveExplorer.Selection.Item(1)
If logit.Class <> olMail Then
MsgBox ("Only mail items can be logged.")
Exit Sub
End If
gUserName = TheCurrentUser()
sFolder = logit.Parent.Name
sconv = logit.ConversationIndex
sfrom = logit.SenderName
ssub = logit.Subject
Set fld = Application.Session.GetDefaultFolder(olFolderInbox)
'This targets my Inbox, I have to find how to use the folder called sFolder from the selected item !!!!! I need to somehow define the fld correctly
strFind = "[ConversationTopic]=" & Chr(34) & logit.ConversationTopic & Chr(34)
Set itms = fld.Items.Restrict(strFind)
icounter = 0
For Each itm In itms
'I'll write the code here.
icounter = icounter + 1
Next
Any help is much appreciated. Thanks