Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SheetChangeEventHandler Problem

Hi everyone!

Im running into a problem using SheetChangeEventHandler.

We need to develop an application that binds to that event. When a cell
value changes we need to get that value and see if it is on a given row and
column and if matches a list of rows and columns we take that value and
insert it in a sql server 2005 table.

The problem we are facing now is that after changing some cells and
inserting the values on sql, the application stops to receive the
SheetChangeEventHandler event. I dont know why, the code seems right but it
keeps happening and the application doesnt catch any exception that might be
thrown. For example, you change one cell and the event fires resulting in the
value inserted in the sql server table. Then you change a few more with the
same results. Then you change another cell and nothing happens, the event
doesnt get fired and as a result the data is not inserted in the sql server
table.

The application is very simple. Is just a Windows Form that shows what is
doing the app, we connect to Excel at Form_Load where we set the delegate for
the event and the event implementation where we get the value and insert it
on the database.

Form_Load
objApp =
(Excel.Application)System.Runtime.InteropServices. Marshal.GetActiveObject("Excel.Application");
objApp.ActiveWorkbook.SheetChange += new
Microsoft.Office.Interop.Excel.WorkbookEvents_Shee tChangeEventHandler(ActiveWorkbook_SheetChange);

Event Implementation
void ActiveWorkbook_SheetChange(object Sh,
Microsoft.Office.Interop.Excel.Range Target)
{
try
{
if (!IsNumeric(Target.Value2))
{
MessageBox.Show("Cell value is not numeric", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string columna_excel = "R" + Target.Row + "C" + Target.Column;
lblmensajes.Text = "Updating data..." + columna_excel;
int result = data.SaveValue(columna_excel,
Convert.ToDecimal(Target.Value2), fecha);
if (result == 0)
{
data.UpdateControlTable(id_proveedor, "ult_actualizacion",
"GetDate()");
lblmensajes.Text = "Data was updated sucessfully.";
}
else
{
data.UpdateControlTable(id_proveedor, "error_int",
result.ToString());
lblmensajes.Text = "Error! Data was not updated.";
}
}
catch (Exception ex)
{
this.messsageForm.AddMessage(ex.ToString());
MessageBox.Show(ex.ToString());
}
}

I hope that anyone can help me.
Thanks in advance!!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"