Banana
08-16-2007, 12:30 PM
I'm building a macro to copy some mail items in Outlook to a specified folder.
I'm trying to build in a check to ensure a same mailitem isn't being added more than once to that specified folder.
I have this code:
Private Function NoDuplicate(ByVal oFolder As Outlook.MAPIFolder, ByVal objItem As Outlook.MailItem) As Boolean
Dim RestrictedItems
Dim oFind As Outlook.MailItem
Dim oItems As Outlook.Items
Dim strSearch As String
Set oItems = oFolder.Items
strSearch = "[Subject] = """ & objItem.Subject & """ AND [CreationTime]= """ & Format(objItem.CreationTime, "ddddd h:nn AMPM") & """
Set oFind = oItems.Find(strSearch)
If oFind Is Nothing Then
NoDuplicate = True
Else
NoDuplicate = False
End If
End Function
Yet, I cannot get it to work. It runs through the code. In the immediate folder, I can check both objItem's creationtime and the actual mailitem's creationtime in that specified folder, and I can tell that they are exactly same.
Yet, the oFind returns as "Nothing" when it should have had that mailitem in the collection! What kind of twisted logic is going on there?!?
PS It still won't work with the Restrict method as well.
I'm trying to build in a check to ensure a same mailitem isn't being added more than once to that specified folder.
I have this code:
Private Function NoDuplicate(ByVal oFolder As Outlook.MAPIFolder, ByVal objItem As Outlook.MailItem) As Boolean
Dim RestrictedItems
Dim oFind As Outlook.MailItem
Dim oItems As Outlook.Items
Dim strSearch As String
Set oItems = oFolder.Items
strSearch = "[Subject] = """ & objItem.Subject & """ AND [CreationTime]= """ & Format(objItem.CreationTime, "ddddd h:nn AMPM") & """
Set oFind = oItems.Find(strSearch)
If oFind Is Nothing Then
NoDuplicate = True
Else
NoDuplicate = False
End If
End Function
Yet, I cannot get it to work. It runs through the code. In the immediate folder, I can check both objItem's creationtime and the actual mailitem's creationtime in that specified folder, and I can tell that they are exactly same.
Yet, the oFind returns as "Nothing" when it should have had that mailitem in the collection! What kind of twisted logic is going on there?!?
PS It still won't work with the Restrict method as well.