A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Prevent duplicates from being entered into the Task list



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 30th 08, 04:09 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Prevent duplicates from being entered into the Task list

I decided to start a new post because my other was answered, and I was
starting to get off the initial topic with a new question. How can I prevent
duplicates from being entered into the Task list? I may open an Excel tool on
Monday and update tasks for individuals. By the end of the week, as some time
has passed and new tasks are required, but some remain the same (or may not
be done until the following week, or instance), I want to run the code again,
but I don't want to enter the same name and time into my Task list (because
it is already there). I only want to enter the name and time if the name
and/or time is different. Can this be done? I am controlling everything from
Excel.

Below is my code; everything works fine...just want to set up a method to
prevent duplicate Tasks from being entered into the Task list in Outlook:
Sub GetOutlookReference()

Range("K2:K100").Clear
Range("E2:E100").Select
Selection.Copy
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "m/d/yyyy"
Range("A1").Select


'Outlook objects
Dim olApp As Outlook.Application

'Obtain a reference to Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'*********************************************
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

i = 2
j = 2
k = 2
l = 2

Do Until Cells(i, 5).Value = ""
'*********************************************
Dim objApp As Object
Dim OutTask As Object

Set objApp = CreateObject("Outlook.Application")
Set OutTask = objApp.CreateItem(olTaskItem)
With OutTask
.StartDate = Cells(i, 5).Value
.Subject = Cells(j, 3).Value
.Body = Cells(k, 1).Value & " - " & Cells(l, 4).Value
.Importance = olImportanceHigh
'.Display
.ReminderSet = True
'.ReminderTime = [NextPM]
'.DueDate = [NextPM]
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
'.Close
End With
'*********************************************
l = l + 1
k = k + 1
j = j + 1
i = i + 1
Loop

'If Outlook isn't running, start it and remember
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If

' If Outlook still isn't running, Outlook cannot open or is not installed
If olApp Is Nothing Then
Call MsgBox("Outlook could not be opened. Exiting macro.", _
vbCritical, Application.Name)
End If

'Send the emial from here
If Range("L1").Value Range("K1").Value Then
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook


With Destwb
If Val(Application.Version) 12 Then

FileExtStr = ".xls": FileFormatNum = -4143
Else

If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Task Roll Ups... " & Sourcewb.Name & " " & Format(Now,
"dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Task Roll Ups"
.Body = "Please see attached..."
.Attachments.Add Destwb.FullName
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub

I feel like a lost sheep; not sure what to do next... Any help would be
greatly appreciated.

Regards,
Ryan--

--
RyGuy
  #2  
Old January 30th 08, 04:21 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Prevent duplicates from being entered into the Task list

Answered already in your other thread.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"ryguy7272" wrote in message
...
I decided to start a new post because my other was answered, and I was
starting to get off the initial topic with a new question. How can I
prevent
duplicates from being entered into the Task list? I may open an Excel tool
on
Monday and update tasks for individuals. By the end of the week, as some
time
has passed and new tasks are required, but some remain the same (or may
not
be done until the following week, or instance), I want to run the code
again,
but I don't want to enter the same name and time into my Task list
(because
it is already there). I only want to enter the name and time if the name
and/or time is different. Can this be done? I am controlling everything
from
Excel.

Below is my code; everything works fine...just want to set up a method to
prevent duplicate Tasks from being entered into the Task list in Outlook:
Sub GetOutlookReference()

Range("K2:K100").Clear
Range("E2:E100").Select
Selection.Copy
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "m/d/yyyy"
Range("A1").Select


'Outlook objects
Dim olApp As Outlook.Application

'Obtain a reference to Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'*********************************************
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

i = 2
j = 2
k = 2
l = 2

Do Until Cells(i, 5).Value = ""
'*********************************************
Dim objApp As Object
Dim OutTask As Object

Set objApp = CreateObject("Outlook.Application")
Set OutTask = objApp.CreateItem(olTaskItem)
With OutTask
.StartDate = Cells(i, 5).Value
.Subject = Cells(j, 3).Value
.Body = Cells(k, 1).Value & " - " & Cells(l, 4).Value
.Importance = olImportanceHigh
'.Display
.ReminderSet = True
'.ReminderTime = [NextPM]
'.DueDate = [NextPM]
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
'.Close
End With
'*********************************************
l = l + 1
k = k + 1
j = j + 1
i = i + 1
Loop

'If Outlook isn't running, start it and remember
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If

' If Outlook still isn't running, Outlook cannot open or is not installed
If olApp Is Nothing Then
Call MsgBox("Outlook could not be opened. Exiting macro.", _
vbCritical, Application.Name)
End If

'Send the emial from here
If Range("L1").Value Range("K1").Value Then
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook


With Destwb
If Val(Application.Version) 12 Then

FileExtStr = ".xls": FileFormatNum = -4143
Else

If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Task Roll Ups... " & Sourcewb.Name & " " & Format(Now,
"dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Task Roll Ups"
.Body = "Please see attached..."
.Attachments.Add Destwb.FullName
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub

I feel like a lost sheep; not sure what to do next... Any help would be
greatly appreciated.

Regards,
Ryan--

--
RyGuy


  #3  
Old January 30th 08, 04:39 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Prevent duplicates from being entered into the Task list

I know you gave me an answer Ken, but I don't know what it means. I googled
around for an answer this morning and I am still without a solution. If you
have a sub, or a function, or something else, please share. Otherwise, I
will just keep searching... Perhaps a solution will present itself soon.

Regards,
Ryan--

--
RyGuy


"Ken Slovak - [MVP - Outlook]" wrote:

Answered already in your other thread.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"ryguy7272" wrote in message
...
I decided to start a new post because my other was answered, and I was
starting to get off the initial topic with a new question. How can I
prevent
duplicates from being entered into the Task list? I may open an Excel tool
on
Monday and update tasks for individuals. By the end of the week, as some
time
has passed and new tasks are required, but some remain the same (or may
not
be done until the following week, or instance), I want to run the code
again,
but I don't want to enter the same name and time into my Task list
(because
it is already there). I only want to enter the name and time if the name
and/or time is different. Can this be done? I am controlling everything
from
Excel.

Below is my code; everything works fine...just want to set up a method to
prevent duplicate Tasks from being entered into the Task list in Outlook:
Sub GetOutlookReference()

Range("K2:K100").Clear
Range("E2:E100").Select
Selection.Copy
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "m/d/yyyy"
Range("A1").Select


'Outlook objects
Dim olApp As Outlook.Application

'Obtain a reference to Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'*********************************************
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

i = 2
j = 2
k = 2
l = 2

Do Until Cells(i, 5).Value = ""
'*********************************************
Dim objApp As Object
Dim OutTask As Object

Set objApp = CreateObject("Outlook.Application")
Set OutTask = objApp.CreateItem(olTaskItem)
With OutTask
.StartDate = Cells(i, 5).Value
.Subject = Cells(j, 3).Value
.Body = Cells(k, 1).Value & " - " & Cells(l, 4).Value
.Importance = olImportanceHigh
'.Display
.ReminderSet = True
'.ReminderTime = [NextPM]
'.DueDate = [NextPM]
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
'.Close
End With
'*********************************************
l = l + 1
k = k + 1
j = j + 1
i = i + 1
Loop

'If Outlook isn't running, start it and remember
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If

' If Outlook still isn't running, Outlook cannot open or is not installed
If olApp Is Nothing Then
Call MsgBox("Outlook could not be opened. Exiting macro.", _
vbCritical, Application.Name)
End If

'Send the emial from here
If Range("L1").Value Range("K1").Value Then
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook


With Destwb
If Val(Application.Version) 12 Then

FileExtStr = ".xls": FileFormatNum = -4143
Else

If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Task Roll Ups... " & Sourcewb.Name & " " & Format(Now,
"dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Task Roll Ups"
.Body = "Please see attached..."
.Attachments.Add Destwb.FullName
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub

I feel like a lost sheep; not sure what to do next... Any help would be
greatly appreciated.

Regards,
Ryan--

--
RyGuy



  #4  
Old January 30th 08, 06:38 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Prevent duplicates from being entered into the Task list

I found this code on the web:
Sub Macro1()
Dim oldTask As TaskItem, newTask As TaskItem, j As Integer

Dim iCounter As Integer

Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items

myItems.Sort "[File As]", olDescending
totalcount = myItems.Count
j = 1
While ((j totalcount) And (myItems(j).Class olTask))
j = j + 1
Wend

Set oldTask = myItems(j)
For i = j + 1 To totalcount
If (myItems(i).Class = olTask) Then
'(newTask.Body = oldTask.Body) And _
Set newTask = myItems(i)
If ((newTask.Subject = oldTask.Subject)) Then
' (newTask.DueDate = oldTask.DueDate) And _
newTask.Mileage = "DELETEME"
iCounter = iCounter + 1
newTask.Save
End If
Set oldTask = newTask
End If
Next i
If iCounter = 0 Then
MsgBox "No duplicate Tasks were detected in " & totalcount & " Tasks!",
vbInformation, "No duplicates"
Else
MsgBox iCounter & " duplicate Tasks were detected and flagged!",
vbInformation, "Duplicates detected"
End If
End Sub

The logic looks sound, and it seems like it should work, but it does not
detect any duplicates in my Tasks folder, and I know there are several
duplicates in the folder. Any thoughts?

Regards,
Ryan---

--
RyGuy


"ryguy7272" wrote:

I know you gave me an answer Ken, but I don't know what it means. I googled
around for an answer this morning and I am still without a solution. If you
have a sub, or a function, or something else, please share. Otherwise, I
will just keep searching... Perhaps a solution will present itself soon.

Regards,
Ryan--

--
RyGuy


"Ken Slovak - [MVP - Outlook]" wrote:

Answered already in your other thread.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"ryguy7272" wrote in message
...
I decided to start a new post because my other was answered, and I was
starting to get off the initial topic with a new question. How can I
prevent
duplicates from being entered into the Task list? I may open an Excel tool
on
Monday and update tasks for individuals. By the end of the week, as some
time
has passed and new tasks are required, but some remain the same (or may
not
be done until the following week, or instance), I want to run the code
again,
but I don't want to enter the same name and time into my Task list
(because
it is already there). I only want to enter the name and time if the name
and/or time is different. Can this be done? I am controlling everything
from
Excel.

Below is my code; everything works fine...just want to set up a method to
prevent duplicate Tasks from being entered into the Task list in Outlook:
Sub GetOutlookReference()

Range("K2:K100").Clear
Range("E2:E100").Select
Selection.Copy
Range("K2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "m/d/yyyy"
Range("A1").Select


'Outlook objects
Dim olApp As Outlook.Application

'Obtain a reference to Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

'*********************************************
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer

i = 2
j = 2
k = 2
l = 2

Do Until Cells(i, 5).Value = ""
'*********************************************
Dim objApp As Object
Dim OutTask As Object

Set objApp = CreateObject("Outlook.Application")
Set OutTask = objApp.CreateItem(olTaskItem)
With OutTask
.StartDate = Cells(i, 5).Value
.Subject = Cells(j, 3).Value
.Body = Cells(k, 1).Value & " - " & Cells(l, 4).Value
.Importance = olImportanceHigh
'.Display
.ReminderSet = True
'.ReminderTime = [NextPM]
'.DueDate = [NextPM]
'.ReminderPlaySound = True
'.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
'.Close
End With
'*********************************************
l = l + 1
k = k + 1
j = j + 1
i = i + 1
Loop

'If Outlook isn't running, start it and remember
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If

' If Outlook still isn't running, Outlook cannot open or is not installed
If olApp Is Nothing Then
Call MsgBox("Outlook could not be opened. Exiting macro.", _
vbCritical, Application.Name)
End If

'Send the emial from here
If Range("L1").Value Range("K1").Value Then
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheet to a new workbook
ActiveSheet.Copy
Set Destwb = ActiveWorkbook


With Destwb
If Val(Application.Version) 12 Then

FileExtStr = ".xls": FileFormatNum = -4143
Else

If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Task Roll Ups... " & Sourcewb.Name & " " & Format(Now,
"dd-mmm-yy h-mm-ss")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = "
.CC = ""
.BCC = ""
.Subject = "Task Roll Ups"
.Body = "Please see attached..."
.Attachments.Add Destwb.FullName
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub

I feel like a lost sheep; not sure what to do next... Any help would be
greatly appreciated.

Regards,
Ryan--

--
RyGuy



  #5  
Old January 30th 08, 08:16 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Prevent duplicates from being entered into the Task list

That code would iterate the entire contents of the folder, which would be
slow if a lot of items are in there.

First decide what properties make the task a duplicate. Then open the Object
Browser and select Items. Go to the Restrict method in the right-hand pane
and click the Help button. That will show you a number of examples of using
Restrict to return a restricted collection of those items that might be
duplicates.

For example you might set your restriction on Subject and on DueDate. The
help shows how to use both string tests and date tests. When you get back
the restricted collection if Count = 0 then you have no potential dupes. If
Count 0 then examine each item in the restricted collection more closely
to decide if it really is a dupe.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"ryguy7272" wrote in message
...
I found this code on the web:
Sub Macro1()
Dim oldTask As TaskItem, newTask As TaskItem, j As Integer

Dim iCounter As Integer

Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items

myItems.Sort "[File As]", olDescending
totalcount = myItems.Count
j = 1
While ((j totalcount) And (myItems(j).Class olTask))
j = j + 1
Wend

Set oldTask = myItems(j)
For i = j + 1 To totalcount
If (myItems(i).Class = olTask) Then
'(newTask.Body = oldTask.Body) And _
Set newTask = myItems(i)
If ((newTask.Subject = oldTask.Subject)) Then
' (newTask.DueDate = oldTask.DueDate) And _
newTask.Mileage = "DELETEME"
iCounter = iCounter + 1
newTask.Save
End If
Set oldTask = newTask
End If
Next i
If iCounter = 0 Then
MsgBox "No duplicate Tasks were detected in " & totalcount & " Tasks!",
vbInformation, "No duplicates"
Else
MsgBox iCounter & " duplicate Tasks were detected and flagged!",
vbInformation, "Duplicates detected"
End If
End Sub

The logic looks sound, and it seems like it should work, but it does not
detect any duplicates in my Tasks folder, and I know there are several
duplicates in the folder. Any thoughts?

Regards,
Ryan---

--
RyGuy


"ryguy7272" wrote:

I know you gave me an answer Ken, but I don't know what it means. I
googled
around for an answer this morning and I am still without a solution. If
you
have a sub, or a function, or something else, please share. Otherwise, I
will just keep searching... Perhaps a solution will present itself soon.


Regards,
Ryan--


  #6  
Old January 31st 08, 03:56 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Prevent duplicates from being entered into the Task list

Hey Ken! Again, thanks for the info. I know I should look in the Object
Browser to understand the Classes and Items better. The Restrict examples
were good, but unfortunately I'm still not getting it. I'm not sure this is
a 'Restrict' issue. I'm not trying to restrict Tasks to a certain type (such
as Business, as shown in the examples). Is it too complex for you to send me
an example on how to count Tasks (i.e. it requires too much customization) or
do you just want me to learn by trial and error how to do this?

This is what I have now, and I still end up with dupes in my Tasks folder:
Dim oldTask As TaskItem, newTask As TaskItem, a As Integer
Dim bCounter As Integer
Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
totalcount = myItems.Count
a = 1
While ((a totalcount) And (myItems(a).Class olTask))
a = a + 1
Wend
Set oldTask = myItems(a)
For b = a + 1 To totalcount

If (myItems(b).Class = olTask) Then
Set newTask = myItems(b)
If ((newTask.Subject = oldTask.Subject)) Then
newTask.Subject = Delete
bCounter = bCounter + 1
newTask.Save
End If
Set oldTask = newTask
End If
Next b
....etc...

I can only assume that the items in the Task folder are not being counted
properly because I can never seem to identify these dupes, and thus I always
end up with several dupes in the Task folder. I believe the whole problem
boils down to this issue. I guess I'll keep at it for a while longer. If
anyone knows how to resolve this issue, please let me know.


Regards,
Ryan--


--
RyGuy


"Ken Slovak - [MVP - Outlook]" wrote:

That code would iterate the entire contents of the folder, which would be
slow if a lot of items are in there.

First decide what properties make the task a duplicate. Then open the Object
Browser and select Items. Go to the Restrict method in the right-hand pane
and click the Help button. That will show you a number of examples of using
Restrict to return a restricted collection of those items that might be
duplicates.

For example you might set your restriction on Subject and on DueDate. The
help shows how to use both string tests and date tests. When you get back
the restricted collection if Count = 0 then you have no potential dupes. If
Count 0 then examine each item in the restricted collection more closely
to decide if it really is a dupe.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"ryguy7272" wrote in message
...
I found this code on the web:
Sub Macro1()
Dim oldTask As TaskItem, newTask As TaskItem, j As Integer

Dim iCounter As Integer

Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items

myItems.Sort "[File As]", olDescending
totalcount = myItems.Count
j = 1
While ((j totalcount) And (myItems(j).Class olTask))
j = j + 1
Wend

Set oldTask = myItems(j)
For i = j + 1 To totalcount
If (myItems(i).Class = olTask) Then
'(newTask.Body = oldTask.Body) And _
Set newTask = myItems(i)
If ((newTask.Subject = oldTask.Subject)) Then
' (newTask.DueDate = oldTask.DueDate) And _
newTask.Mileage = "DELETEME"
iCounter = iCounter + 1
newTask.Save
End If
Set oldTask = newTask
End If
Next i
If iCounter = 0 Then
MsgBox "No duplicate Tasks were detected in " & totalcount & " Tasks!",
vbInformation, "No duplicates"
Else
MsgBox iCounter & " duplicate Tasks were detected and flagged!",
vbInformation, "Duplicates detected"
End If
End Sub

The logic looks sound, and it seems like it should work, but it does not
detect any duplicates in my Tasks folder, and I know there are several
duplicates in the folder. Any thoughts?

Regards,
Ryan---

--
RyGuy


"ryguy7272" wrote:

I know you gave me an answer Ken, but I don't know what it means. I
googled
around for an answer this morning and I am still without a solution. If
you
have a sub, or a function, or something else, please share. Otherwise, I
will just keep searching... Perhaps a solution will present itself soon.


Regards,
Ryan--



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003: Prevent message when set reminder-time for a task Oskar Vaia Outlook - Using Forms 7 November 17th 07 02:54 PM
Why do entered tasks fail to show on calendar's task pad? rll7548 Outlook - Calandaring 1 November 9th 07 12:15 AM
How do I move a Daily Task to the Master Task List? Carol Outlook - General Queries 0 November 17th 06 05:57 PM
Prevent duplicates when importing appointments in Outlook 2003 Ben Ambrosino Outlook - Calandaring 0 September 26th 06 03:33 PM
show all recurrences of a task in the task list dash Outlook - Calandaring 2 April 15th 06 02:45 AM


All times are GMT +1. The time now is 03:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.