Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

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

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
Alok-Agarwal
Asked:
Alok-Agarwal
  • 10
  • 9
1 Solution
 
Chris BottomleyCommented:
>>> 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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
Chris BottomleyCommented:
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
 
Alok-AgarwalAuthor Commented:
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
 
Chris BottomleyCommented:
>>> 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
 
Alok-AgarwalAuthor Commented:
After the paste operation application.activeexplorer.selection.count is just returning value as 1 irrespective of how many items I copy & paste
0
 
Chris BottomleyCommented:
>>> 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now