473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Loosing event handlers in word

Hi all!
I'm developing an application to manage word templates and documents.
Documents are stored in database, so when user wants to edit a document
i make a local copy of this document and then open it through ms word.
I have handlers for beforeClose, beforeSave and Quit events. The
problem is following: i open any number of documents for editing, then
edit any document (say, document A) and don't save it (by ctrl+s, save
button e t.c.) and then close it (by alt+f4, close button) then my
application catch _only_ beforeClose event for document A (quit event
is not handled). For other opened documents application doesn't catch
any events at all. So now i can close all opened documents. After it i
can open documents again and _only now_ all event handlers work for
opened documents.

Here is the code i used

//adding handlers
....
app.DocumentBeforeClose += new
Microsoft.Office.Interop.Word.ApplicationEvents4_D ocumentBeforeCloseEventHandler(app_DocumentBeforeC lose);
app.DocumentBeforeSave += new
Microsoft.Office.Interop.Word.ApplicationEvents4_D ocumentBeforeSaveEventHandler(app_DocumentBeforeSa ve);
app.ApplicationEvents2_Event_Quit += new
Microsoft.Office.Interop.Word.ApplicationEvents2_Q uitEventHandler(app_ApplicationEvents2_Event_Quit) ;
.....

//handler for beforeClose event
private void
app_DocumentBeforeClose(Microsoft.Office.Interop.W ord.Document Doc, ref
bool Cancel)
{
//MessageBox.Show("Event BeforeClose");
//here i check if it is my application's
document or not
if (IsIMTemplate(Doc))
{
this.IMTemplateCheckedOut = false;
if (Doc.Saved)
{
this.imTemplateNeedUpdating = false;
}
else
{
DialogResult dialogResult;
//formDBC - just a form with 3
buttons Yes, No, Cancel
frmDialogBeforeClose formDBC = new frmDialogBeforeClose();
formDBC.TopMost = true;

formDBC.Focus();

dialogResult = formDBC.ShowDialog();

//do nothing
if (dialogResult == DialogResult.Cancel)
{//
Cancel = true;
this.IMTemplateCheckedOut = true;
}

//close documnet without updating it in database
if (dialogResult == DialogResult.No)
{
this.imTemplateNeedUpdating = false;
object saveChanges = false;
object optional = Missing.Value;
Word.ApplicationClass tmpApp = (Word.ApplicationClass)Doc.Parent;
Doc.Close(ref saveChanges, ref optional, ref optional);
tmpApp.Quit(ref saveChanges, ref optional, ref optional);
}

//close with updating in database
if (dialogResult == DialogResult.Yes)
{
this.imTemplateNeedUpdating = true;
Doc.Save();
}
formDBC.Dispose();
}//else
}
}

also i have handlers for other events but i think the problem somewhere
else...
Thnx in advance.

Apr 5 '06 #1
0 2153

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
5
by: Action | last post by:
does it works like ordinary virtual method?? coz I find that child class can't invoke the event of the parent class. class parent { public virtual event SomeDelegate SomeChanged; } class...
5
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
5
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.