Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / October 2005

Tip: Looking for answers? Try searching our database.

tasks being renamed when moving to archive folder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vonclausowitz@gmail.com - 10 Oct 2005 15:56 GMT
I use this code to get a single or multiple selection of tasks and then
when hitting Delete move them to a folder named "Taken Oud". The
problem is that they all get renamed to the same name. What am I doing
wrong?

Dim garrTask()

Private Sub oExplorer_SelectionChange()

Dim i As Integer

If oExplorer.CurrentFolder.DefaultItemType = olTaskItem Then
   For i = 1 To oExplorer.Selection.Count
       ReDim garrTask(oExplorer.Selection.Count)
       Set oTask = oExplorer.Selection(1)  ' init first item to start
with
       Set garrTask(i) = oExplorer.Selection(i)   ' store in a global
array
       MsgBox "" & garrTask(i)
   Next
End If

End Sub

Private Sub oTasks_ItemRemove()

Dim myCopiedItem As Outlook.TaskItem
Dim olOldFolder As String
Dim i As Integer
olOldFolder = objDestinationFolder

For i = 1 To oExplorer.Selection.Count
   ReDim garrTask(oExplorer.Selection.Count)
   If oTask.Complete = True Then
       MsgBox "Do you want to move " & oTask & " to " & olOldFolder &
" ?"
       Set myCopiedItem = oTask.Copy
       myCopiedItem.Move objDestinationFolder
   End If
Next

End Sub

Regards
Marco
Ken Slovak - [MVP - Outlook] - 10 Oct 2005 18:20 GMT
Use a count down loop when you move items:

For i = lCount To 1 Step -1

Also, move is a function that returns an object.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

>I use this code to get a single or multiple selection of tasks and then
> when hitting Delete move them to a folder named "Taken Oud". The
[quoted text clipped - 41 lines]
> Regards
> Marco
vonclausowitz@gmail.com - 10 Oct 2005 18:26 GMT
How should I use that line in my code?

What do you mean with Move is a function that returns an object.
What ain't right with what I wrote?

Marco
Michael Bauer - 11 Oct 2005 07:30 GMT
Am 10 Oct 2005 10:26:53 -0700 schrieb vonclausowitz@gmail.com:

Marco, please have a look at your code. I´m sure you can find the line with
the For-Next statement where the items are being moved and replace it with
Ken´s suggestion.

In addition:

1) You don´t set oTask, but copy and move always the same oTask within the
loop. Therefor all your moved items have the same name. You should set oTask
to Selection(i) within the loop.

2) Your code doesn´t move the TaskItem, but a copy of it. That is, the
original item remains in the folder. So move the Item itself instead of its
copy.

3) It looks like you want to ask the user whether the Item should be moved
or not but you don´t. Use this instead:

If MsgBox("...", vbYesNo + vbQuestion) = vbYes Then
    ' move
Endif

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

> How should I use that line in my code?
>
> What do you mean with Move is a function that returns an object.
> What ain't right with what I wrote?
>
> Marco
vonclausowitz@gmail.com - 11 Oct 2005 18:22 GMT
Michael,

There are some things I don't understand.
first of all the copy and move thing I put in because just moving
returned an error,
but maybe that had to do with my wrong prgramming.

This is the code I have now but still some things are bothering me.

For i = lCount To 1 Step -1
   Set oTask = oExplorer.Selection(i)
   ReDim garrTask(oExplorer.Selection.Count)
   If oTask.Complete = True Then
      If MsgBox("Do you want to move this task?", vbYesNo +
vbQuestion) = vbYes Then
           MsgBox "Do you want to move " & oTask & " to " &
olOldFolder & " ?"
            oTask.Move objDestinationFolder
      End If
   End If
Next

I pressume the lCount is an integer.
But what does the line do? lCount to 1 step -1?
Where do I start with lCount? Is it 0 or 1 or else....?
Should I add 1 to lCount everytime I remove an item?

Sorry guys but I'm lost.

Marco
vonclausowitz@gmail.com - 11 Oct 2005 20:48 GMT
Ok, I changed the code to this:

Private Sub oTasks_ItemRemove()

Dim olOldFolder As String
Dim i, lCount As Integer
olOldFolder = objDestinationFolder

For i = oExplorer.Selection.Count To 1 Step -1
   Set oTask = oExplorer.Selection(i)
   ReDim garrTask(oExplorer.Selection.Count)
   If oTask.Complete = True Then
      If MsgBox("Do you want to move this task?", vbYesNo +
vbQuestion) = vbYes Then
            oTask.Move objDestinationFolder
      End If
   End If
Next

ReDim garrTask(0)  'maak de array leeg

End Sub

Only problem? It catches the tasks when the task which has to be moved
is already deleted and so it is stuck with the task which has the focus
after the other one has been deleted.... that's too late. I want to
catch the task i deleted.

Marco
Michael Bauer - 12 Oct 2005 07:39 GMT
Am 11 Oct 2005 12:48:17 -0700 schrieb vonclausowitz@gmail.com:

Marco, please insert in the very first line of your "ThisOutlookSession"
module this: Option Explicit

These two words force you to declare every variable. Then neither you nor
the compiler has to suppose about variables. (For new modules VBA can write
the lines automatically, just check Tools->Options->Declaration of variables
necessary (the second CheckBox).

> Dim i, lCount As Integer

In VB(A) the type must be named for every variable. If that´s missing the
variable wil be of a standard type (usually a variant).

> Only problem? It catches the tasks when the task which has to be moved
> is already deleted and so it is stuck with the task which has the focus
> after the other one has been deleted.... that's too late. I want to
> catch the task i deleted.

I don´t really understand what you´re trying to do. Because of the array
garrTask I suppose you want to store every TaskItem in the array before it
is being moved, don´t you?

Actually the array is free of any sense. First you don´t store anything in
the array, second the ReDim statement re-dimensions the array - that is all
its content is being deleted.

Solution:

Please place the ReDim... line outside of the loop. Doing so the statement
will be called just once.

Usually the lower array bound has a value of 0. ReDim arr(3) then will have
a range from 0 to 3, that is 4 elements.

For having the same array bounds as for the Explorer.Selection you can
explicitly name that: ReDim arr(1 to 3) will have a range from 1 to 3, that
is 3 elements.

As Ken already mentioned, the Move function returns an object. If you want
to store the moved TaskItem in your array then just write in the loop:

Set garrTask(i)=oTask.Move(objDestinationFolder)

> ReDim garrTask(0)  'maak de array leeg

This again deletes all array elements...

(If you want to ReDim an array without loosing its content then use ReDim
Preserve instead and increase its upper bound.)

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

> Ok, I changed the code to this:
>
[quoted text clipped - 25 lines]
>
> Marco
vonclausowitz@gmail.com - 12 Oct 2005 14:48 GMT
Michael,

I think we have to go back to sratch because this thing is getting way
out of my head. There are to many problems occuring I have to settle
with first otherwise it is useless to get this thing going.

I will try to explain what my problems are, hopefully you have some
solutions for me.

1. We have a shared email account (four people working on the same
tasks);
2. We use a user defined field named "Updater";
3. We use the field "Subject" to store a filename, for example
(MY.FILENAME.)
3. We use the field "Role" to store the date (as a string) of the last
time we got this file named in "Subject";
4. What we want is the following:
  - when someone (of those four) changes a task (either the date in
the field "Role" or when he clicks a task as "Completed"), the user
defined field "Updater" should be updated automatically with: MYNAME +
Date();

Now for the problems:

1. When someone changes something in one of the tasks my own ItemChange
will detect this and put MYNAME + Date() in the Updater field, although
I did'nt change anything;
2. When I click a task as Completed it will dissapear and a new task
will show up, since we set reccurrence for every day, the new task will
have Due Date of tomorrow. Since reccurrence acts first i'm not able to
update the Updater field anymore;
3. The update in ItemChange will first take place when the item has
lost its focus.

So we need something to make sure that the task is only updated if I
changed something and not of my neighbours does, and two, I need a way
to update the field "Updater" before the task is clicked awy as
Completed.

Can this be done, or even, does this all make sense to you?

Marco

Michael Bauer schreef:

> Am 11 Oct 2005 12:48:17 -0700 schrieb vonclausowitz@gmail.com:
>
[quoted text clipped - 81 lines]
> >
> > Marco
David C. Holley - 13 Oct 2005 23:41 GMT
It sounds as if the tasks are assigned to more than 1 person, which if I
understand it will cause changes to cascade from one to another. The
idea being that Outlook wants you to be aware that person 1 updated a
task and so your task receives the update as well. If you're using
Exchange, is the possibility of creating an Exchange folder to hold all
of the tasks as opposed to each person being assigned to the task? That
will probably fix the problem.

> Michael,
>
[quoted text clipped - 126 lines]
>>>
>>>Marco
vonclausowitz@gmail.com - 14 Oct 2005 13:13 GMT
David,

For some internal reasons an Exchange folder is not an option.
What I'm looking at now is:

the use of oExplorer.Selection(1) and ItemChange and PropertyChange.

First of all when a Task changes let the system detect which user
caused the change and then with the current selected Item try to find
out what field was changed to which value.

The only problem is I don't know how to get this into code...

Marco

David C. Holley schreef:

> It sounds as if the tasks are assigned to more than 1 person, which if I
> understand it will cause changes to cascade from one to another. The
[quoted text clipped - 134 lines]
> >>>
> >>>Marco
David C. Holley - 14 Oct 2005 18:59 GMT
That then would be out of my league. You'll probably have to devel
deeper in to the Outlook Object Model to figure out how to deal with the
situation.

> David,
>
[quoted text clipped - 151 lines]
>>>>>
>>>>>Marco
Michael Bauer - 15 Oct 2005 09:04 GMT
Am 14 Oct 2005 05:13:12 -0700 schrieb vonclausowitz@gmail.com:

So far I don´t understand your system. Are all of the four are working on
the same *.pst file?

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

> David,
>
[quoted text clipped - 151 lines]
>>>>>
>>>>>Marco
vonclausowitz@gmail.com - 15 Oct 2005 09:40 GMT
We use a shared mailbox called DIGINFO. My own mailbox is DIGINFO4.
In this shared mailbox we use the tasks. So if that means we are using
the same pst file, Yes.

This is the way the system is setup. Good or bad we have to live with
it.

Marco
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.