Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Problem with Error Handler routing?

I have a userform in Excel that requires a user to select an option from a
drop down combobox. A command button returns the value and opens up another
workbook for the user to edit. I added an error handling routine that
returns an error message if for some reason the file doesn't exist or there
is a problem with the file path. My problem is that even when the sub runs
successfully, I still get the error message. If I completely remove the
error handling routine and line code, I get no vba/excel errors, but the sub
runs successfully. I am not sure why I get the error message upon successful
completion of the sub?

Here is my code. Any help would be appreciated!

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC ("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub

--
Thanks,

Gerry O.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Problem with Error Handler routing?

Gerry,

You need to add an "Exit Sub" line before your "errorhander" code label.
Without it, execution carries merrily along into the error handler code.
E.g.,


Exit Sub
ErrorHandler:
MsgBox("Error")
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Gerry O" wrote in message
...
I have a userform in Excel that requires a user to select an option from a
drop down combobox. A command button returns the value and opens up
another
workbook for the user to edit. I added an error handling routine that
returns an error message if for some reason the file doesn't exist or
there
is a problem with the file path. My problem is that even when the sub
runs
successfully, I still get the error message. If I completely remove the
error handling routine and line code, I get no vba/excel errors, but the
sub
runs successfully. I am not sure why I get the error message upon
successful
completion of the sub?

Here is my code. Any help would be appreciated!

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC
("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub

--
Thanks,

Gerry O.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Problem with Error Handler routing?

You need to exit sub otherwise your code will continue on into your
errorhandler...

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC ("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False
Exit Sub '***************

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub


--
HTH...

Jim Thomlinson


"Gerry O" wrote:

I have a userform in Excel that requires a user to select an option from a
drop down combobox. A command button returns the value and opens up another
workbook for the user to edit. I added an error handling routine that
returns an error message if for some reason the file doesn't exist or there
is a problem with the file path. My problem is that even when the sub runs
successfully, I still get the error message. If I completely remove the
error handling routine and line code, I get no vba/excel errors, but the sub
runs successfully. I am not sure why I get the error message upon successful
completion of the sub?

Here is my code. Any help would be appreciated!

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC ("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub

--
Thanks,

Gerry O.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Problem with Error Handler routing?

Big "duh" on my part. Thanks for the quick response. Works perfectly now!
--
Thanks,

Gerry O.


"Chip Pearson" wrote:

Gerry,

You need to add an "Exit Sub" line before your "errorhander" code label.
Without it, execution carries merrily along into the error handler code.
E.g.,


Exit Sub
ErrorHandler:
MsgBox("Error")
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Gerry O" wrote in message
...
I have a userform in Excel that requires a user to select an option from a
drop down combobox. A command button returns the value and opens up
another
workbook for the user to edit. I added an error handling routine that
returns an error message if for some reason the file doesn't exist or
there
is a problem with the file path. My problem is that even when the sub
runs
successfully, I still get the error message. If I completely remove the
error handling routine and line code, I get no vba/excel errors, but the
sub
runs successfully. I am not sure why I get the error message upon
successful
completion of the sub?

Here is my code. Any help would be appreciated!

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC
("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub

--
Thanks,

Gerry O.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Problem with Error Handler routing?

Chip Pearson pointed out the same thing. Didn't eat my Wheaties this
morning. Thanks for the quick response!!
--
Thanks,

Gerry O.


"Jim Thomlinson" wrote:

You need to exit sub otherwise your code will continue on into your
errorhandler...

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC ("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False
Exit Sub '***************

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub


--
HTH...

Jim Thomlinson


"Gerry O" wrote:

I have a userform in Excel that requires a user to select an option from a
drop down combobox. A command button returns the value and opens up another
workbook for the user to edit. I added an error handling routine that
returns an error message if for some reason the file doesn't exist or there
is a problem with the file path. My problem is that even when the sub runs
successfully, I still get the error message. If I completely remove the
error handling routine and line code, I get no vba/excel errors, but the sub
runs successfully. I am not sure why I get the error message upon successful
completion of the sub?

Here is my code. Any help would be appreciated!

Private Sub cmbEnter_Click()
Dim CostCenter
CostCenter = cbxCostCenter.Value

On Error GoTo errorhandler

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Budget 2008 - AMC ("
& CostCenter & ").xls", _
UpdateLinks:=1
Unload Me
'ResetAll
'ThisWorkbook.Close savechanges:=False

errorhandler:
MsgBox ("Application cannot load file. Contact Application
Administrator for assistance.")

End Sub

--
Thanks,

Gerry O.

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
VBA Error Handler MVM Excel Programming 1 June 12th 06 07:56 PM
Form Err.Raise error not trapped by entry procedure error handler [email protected] Excel Programming 1 February 8th 06 10:19 AM
Routing - macro to open routing dialog and then stop Mike R. Excel Programming 1 December 18th 04 02:41 AM
Error Handler dht[_2_] Excel Programming 5 August 19th 04 08:51 AM
error handler Fleur Excel Programming 1 November 20th 03 06:06 AM


All times are GMT +1. The time now is 12:53 PM.

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"