Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default error handling for network connections

Hi,

I have a large spreadsheet that the user 'synchronises' with a db on a
remote network. After 'synchronising' (ie. connecting over the network
to the db, and retrieving the required data) the sheet then runs a
large amount of code to update from the data it has just retrieved.

Occasionally the network connection drops during the sync and the code
stops with an error (obviously). This would not be a problem if the
user could simply re-connect to the network and try again, however as
this halts my code in the middle, the code has not reached the end
line (enable events = true) and so they cannot use any of the cells
on the sheet that are designed for navigation / running code.
Therefore they cannot 'sync' the sheet again as the cell on the sheet
that activates the 'sync' code is disabled.

So I need to learn how to do error handling. However on trying this
(at the start of the sync code 'on error goto 0', and at the end of
the sub 0: application.enableevents = true, exit sub) this does not
work and I have the same problem.

Please can somebody help me out.

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default error handling for network connections

On error Goto 0 is intended to return th esystem back to it's default error
handling. Try something more like this...

Sub Whatever
On error goto Errorhandler:
Application.enableevents = false
'your code here

Errorhandler:
Application.enableevents = true
End sub

If there is an error the code will drop down and execute the Errorhandler
code. If no error is encountered then execution will proceed through all of
the normal code and then through the errorhandler code. This way Events will
always get turned back on...
--
HTH...

Jim Thomlinson


"keri" wrote:

Hi,

I have a large spreadsheet that the user 'synchronises' with a db on a
remote network. After 'synchronising' (ie. connecting over the network
to the db, and retrieving the required data) the sheet then runs a
large amount of code to update from the data it has just retrieved.

Occasionally the network connection drops during the sync and the code
stops with an error (obviously). This would not be a problem if the
user could simply re-connect to the network and try again, however as
this halts my code in the middle, the code has not reached the end
line (enable events = true) and so they cannot use any of the cells
on the sheet that are designed for navigation / running code.
Therefore they cannot 'sync' the sheet again as the cell on the sheet
that activates the 'sync' code is disabled.

So I need to learn how to do error handling. However on trying this
(at the start of the sync code 'on error goto 0', and at the end of
the sub 0: application.enableevents = true, exit sub) this does not
work and I have the same problem.

Please can somebody help me out.

Thanks,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default error handling for network connections

Oops... the statement
On error goto Errorhandler:
should exclude the colon like this...
On error goto Errorhandler

sorry for any confusion...
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

On error Goto 0 is intended to return th esystem back to it's default error
handling. Try something more like this...

Sub Whatever
On error goto Errorhandler:
Application.enableevents = false
'your code here

Errorhandler:
Application.enableevents = true
End sub

If there is an error the code will drop down and execute the Errorhandler
code. If no error is encountered then execution will proceed through all of
the normal code and then through the errorhandler code. This way Events will
always get turned back on...
--
HTH...

Jim Thomlinson


"keri" wrote:

Hi,

I have a large spreadsheet that the user 'synchronises' with a db on a
remote network. After 'synchronising' (ie. connecting over the network
to the db, and retrieving the required data) the sheet then runs a
large amount of code to update from the data it has just retrieved.

Occasionally the network connection drops during the sync and the code
stops with an error (obviously). This would not be a problem if the
user could simply re-connect to the network and try again, however as
this halts my code in the middle, the code has not reached the end
line (enable events = true) and so they cannot use any of the cells
on the sheet that are designed for navigation / running code.
Therefore they cannot 'sync' the sheet again as the cell on the sheet
that activates the 'sync' code is disabled.

So I need to learn how to do error handling. However on trying this
(at the start of the sync code 'on error goto 0', and at the end of
the sub 0: application.enableevents = true, exit sub) this does not
work and I have the same problem.

Please can somebody help me out.

Thanks,


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
External Data Connections Error Steph2010 Excel Discussion (Misc queries) 0 February 10th 10 05:25 AM
ADODB.Connections Error confused-as-usual Excel Programming 1 October 26th 06 05:44 PM
UDF Error Handling is ignored. Not for everyone? [email protected] Excel Programming 4 March 22nd 06 06:31 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM


All times are GMT +1. The time now is 08:27 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"