Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Kuhaylah Malik   on Jan 29 In MS Office Category.

  
Question Answered By: Daniel Evans   on Jan 29

You are always going to run the error  code unless you get out.

Try...

Private Sub cmdAdd_Click()

On Error GoTo errmsg

// main  code: calculation  work perform  here.

On Error GoTo 0

Exit sub ' Get out of here!!!!

errmsg:
MsgBox "Adding can't execute  due to the textbox  is empty.", vbOKOnly )

End Sub

In this particular case though... Why not just test to see if there is any
text in the text box?



Error handling comes up quite frequently on these lists and a lot of it is
down to personal preference. *My* preference FWIW is to deal with each error
seperately and "in line".

Option Explicit
Public igErrNum as integer
----------------

Sub subSomeSub

On Error Resume Next
// Single Line of code  that could error
igErrNum = Err.Number
On error goto 0
Select case igErrNum
Case 0
Case ....
Case ....
Case else
End select

Repeat for each line that could error.

End Sub

If anyone wants to jump in here with their own preferences please do feel
free to do so!

Share: 

 
 
Didn't find what you were looking for? Find more on Error handler Or get search suggestion and latest updates.


Tagged: