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
Prev Previous Post   Next Post Next
  #8  
Old February 4th 08, 07:05 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Prevent duplicates from being entered into the Task list

Resolved:
http://www.microsoft.com/office/comm...r=US&sloc=&p=1



--
RyGuy


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

Well, first of all for Restrict it would be something like this, assuming
your test is on Subject:

' previous code
Set myItems = myFolder.Items
Dim colRestrict as Outlook.Items
Set colRestrict = myItems.Restrict("[Subject] = " & Chr(34) &
newTask.Subject & Chr(34))
If colRestrict.Count = 0 Then ' no items with that Subject
'blah, blah, whatever
Else ' there is at least one dupe
' find the dupe and delete it
If colRestrict.Count = 1 Then
colRestrict.Items(1).Delete
Else
For i = colRestrict.Count To 1 Step -1
colRestrict.Items(i).Remove
Next
End If

When deleting items from a collection using a For loop never use a count up
loop. As you delete the index gets decremented so you will miss 1/2 of the
items. Use a count down loop as shown.

I think that Restrict example on Subject is probably the sort of thing you
need.

--
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
...
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--



 




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:38 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.