Solved

How to find if item change/add event for all copied appoinments in All Appointments view is completed

Posted on 2009-05-14
20
306 Views
Last Modified: 2012-05-07
Hi,

I have created an addin in outlook 2007. I want to show a form to a user to take a decision whenever a new appointment is created or any existing appointment is changed. This works fine . However when I have two calendars say Test and actual calendar and I go to View All appointment in test calendar, copy say around 20 to 30 appointments and paste them in actual calendar's "All Appointment items view", the form created by me start coming up once for each item. I introduced a global varibale to ensure that the form comes only once for this kind of bunch handling, however the variable is not gettting initialized for the next bunch. i.e. once the first bunch is over if I copy in the same fashion another bunch the application just behaves depending upon the decision I took for the first bunch. I want that global variable should be re-initilized for the next bunch but not clear where exactly I should do this.

In bunch copy operation the form pops up , asking if a particular operation needs to be performed for that appointment item. The answer to this question can be yes, yes to all, no , no to all . Yes perform the operation and asks me again for the next item in the same bunch Yes to all means,apply the operation for each item in that bunch and do not show form again. No means, do not apply operation for that appointment item and form to come up again for the next item in the same buch No to all means do not perform the operation for any item, The form should not popup again

However for the second bunch the decision I am taking is just carried forward , so if first time I said no to all, the form is not cmong up at all for the next bunch also

I want that question of yes, yes to all, no , no to all should be applied to each bunch of appointment item separately. i.e. one bunch should not be mixed with other. I presume the problem is which place to use to re-initalize the global variable that I have set during first bunch
0
Comment
Question by:Alok-Agarwal
  • 10
  • 9
20 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24392653
>>> I presume the problem is which place to use to re-initalize the global variable that I have set during first bunch

I would say so, but unless we see the code it will be difficult to help ... therefore can you supply the code?

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24392719
Hi,

I have created a class says ClassApp and following is how I have created a variable withevents as follows in the class

Private WithEvents m_objFolderItems As Items

Private Sub m_objFolderItems_ItemAdd(ByVal Item As Object)
  Call  DoProcessing(item)
End Sub

Private Sub m_objFolderItems_ItemChange(ByVal Item As Object)
 Call  DoProcessing(item)
End Sub

In the DoProcessing I am using a global variable,

Private Sub DoProcessing ()
show form
depending upon the response (i.e. which button is clicked) on the form assign the value to global variable and do some other processing
End Sub


So all this is working fine, till I move to next bunch. I presume that events ItemAdd and ItemChange are triggered autmatically as I copy/paste lot of appointments at one go. However I need a way to find out that operation on the first bunch is completed and now it is time to re-initilize the global variable so that next bunch do not have a issue.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24392797
What defines a group, noting your comment "I need a way to find out that operation on the first bunch ".

As long as a group is the range of items dropped in one go then as part of the itemadd or itemchange events before calling doprocessing set the global to your default setting.

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24392836
The bunch is basically the number of items copy/pasted at one go. So if a user copied 20 appointments then group is bunch of those 20 appointments. I tried to re-set global variable before DoProcessing but then the form is coming up for each item in the first buch also (even when I say "yes to all" on the promot on first item). If you go through my original description if I say "yes to all" on the first item in the bunch the form should not come up for rest of the items in that bunch.

However the form should again come up when I say move onto copy another set of 50 appointments items. Is there soemthing which needs to be done using objects like Explorer, Inspector etc..
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24392847
I'd have to see the code in the form and perhaps doprocessing to see what is happening because I would expect that setting the status on the form will be memorised therefore perhaps the scope of the global is being affected by using a local copy in the relevant code.

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24392883
I am not using any local copy of the variable, i am using global variable. Whatever value is set on the form the same gets used in DoProcessing.

Actually I don' think we have control on ItemAdd / itemChange events which gets triggered immediately after copy/paste is done. Earlier when code changes were done, the form was coming up for each item in the bunch. As this was irritating to the end user the code change was done so that user do not get the form again if he decides "Yes to All" on the first item itself.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24392978
For the purposes of resetting the variable you do have control over the events insofar as when they are triggered you use the subs to do something i.e.

Private Sub m_objFolderItems_ItemAdd(ByVal Item As Object)
  set global = ""
  Call  DoProcessing(item)
End Sub

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24393042
The piece of code suggested by you is bringing the form again and again for each item in the same bunch. It should not do that if response from user after the form is shown to the end usre for first item is 'Yes to All" or "No to all". However if the response is either of Yes or No then it is ok to bringup the form till the user responds with "Yes to all" or "No to all"
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24393143
Okay then please recall that I am working in the blind here without the actiual source therefore what I now understand is when you select a range, the add event is triggered once for each datum.

Therefore there must be something in your doprocessing that sets the variable - reasonable from my interpreatation of what is happening.

When changing a group can you identify how it happens, i.e. copy paste or such as the answer may lie in using that event to trigger a flag before and after.

Chris
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24393404
ok, let us put the question this way. Is there a way to figure out a count of how many items have been copy pasted if user does the activity as I mentioned above

i.e.
when a user has two calendars say Test and actual calendar and he goes to View All appointment in test calendar, copy say around 20 to 30 appointments and paste them in actual calendar's "All Appointment items view. can we get a message box saying so many items copied.
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24393422
And to add further to my comment above if the copy/paste is again repeated for another 50 appointment items then message box should show 50 (this count should come correctly without the need to close outlook or terminate the session
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24393444
That is where I am coming from ...

Assuming that a number of items are selected then when selected the count of items is given by:

application.activeexplorer.selection.count, therefore if you pick that up in your script and then count entries to dosomething you could use that to reset the global when equal.

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24393455
yes, that looks great idea but where should I put in the piece of code application.activeexplorer.selection.count

I mean if someone was just making a small outlook 2007 add-in for this message box functionaltiy only where exactly he would put the above line of code
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24393489
Sorry to keep emphasising but it is difficult without the full code however I would suggest

In DoProcessing have a static variable for itemstodo.

On entry to DoProcessing, look at itemstodo and if it is zero then set it to the selection count.
Within doprocessing do whatever it is you do then decrement itemstodo.  

Next time in if there were 2 items originally then on entry itemstodo = 1 so it is not changed, it repeats the activity, sets itemstodo to zero ready for the next group

Therefore after decrementing itemstodo if it is zero clear your global and it should be triggered with the next group.

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24393519
Note  it would look something like:

sub DoProcessing()
    Static itemstodo As Integer
    ifitemstodo = 0 then itemstodo = application.activeexplorer.selection.count
'existing code
   itemstodo = itemstodo - 1
   if itemstodo = 0 then myglobal = ""
end sub

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24393575
I am away from my PC, let me try this and would let you know. Can the static variable be declared in procedure in a VB 6.0 class
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24393720
>>> the static variable be declared in procedure in a VB 6.0 class

Honest answer, I don't know but static variables are a common feature of programming BUT if not just create it as another global ... I only suggested static as I try to avoid globals when I can.

Chris
0
 
LVL 5

Author Comment

by:Alok-Agarwal
ID: 24400285
After the paste operation application.activeexplorer.selection.count is just returning value as 1 irrespective of how many items I copy & paste
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 24400974
>>> After the paste operation application.activeexplorer.selection.count is just returning value as 1

Makes sense to me but why is it significant, in all my tests teh selection.count reflects the number of selected items so will be correct on entry to the event additems or changeitems.  Of course I am assuming the content of the routines so just in case try making the itemstodo global and moving the test to add or change item subs.  The actual test might not be necessary but try keeping it initially.

Chris
Private WithEvents m_objFolderItems As Items

dim itemstodo As Integer
 

Private Sub m_objFolderItems_ItemAdd(ByVal Item As Object)

    ifitemstodo = 0 then itemstodo = application.activeexplorer.selection.count

  Call  DoProcessing(item)

End Sub
 

Private Sub m_objFolderItems_ItemChange(ByVal Item As Object)

    ifitemstodo = 0 then itemstodo = application.activeexplorer.selection.count

 Call  DoProcessing(item)

End Sub
 

sub DoProcessing()

'existing code

   itemstodo = itemstodo - 1

   if itemstodo = 0 then myglobal = ""

end sub

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now