Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error message

Posted on 2012-03-22
5
Medium Priority
?
225 Views
Last Modified: 2012-03-23
I have attached an error message, has anyone any code that if that particular error arises i can give the user an msgbox "xyz" and then exits sub

Thanks
Seamus
Doc4.doc
0
Comment
Question by:Seamus2626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Frank White
ID: 37753614
I think the attachment might have been mixed up. Seems to be from a previous question, in fact.

As for catching the error, here's an excellent tutorial on VBA error handling..

As shown there, you can use On Error GoTo ErrHandler: and If Err.Number = # statements to catch a particular error and do some action. You can also use use both your own error handler and the default one by adding "On Error GoTo 0" and then "Resume" statements at the end of your error handling block, which reverts to normal error-catching and then retries the line that caused an error.
0
 

Author Comment

by:Seamus2626
ID: 37753629
Oops sorry, correct attachment
Doc4.doc
0
 
LVL 3

Accepted Solution

by:
Frank White earned 2000 total points
ID: 37753856
The way I would go about this is:

'Function/sub declaration, variables, etc.
On Error GoTo ErrHandler:

'Your code including the code that produces that error.

ErrHandler:
    MsgBox Err.Number
    On Error GoTo 0
    Resume
'End function/sub

Open in new window


Then, run it once and the message box should tell you the right number to put in the following code:

'Sub declaration, variables, etc.
On Error GoTo ErrHandler:

'Your code including the code that produces that error.

ErrHandler:
    If Err.Number = ((**ERRORNUMBER**)) Then 
        MsgBox "Not enough memory left!"
        On Error GoTo 0
        Exit Sub
    End If
    On Error GoTo 0
    Resume

End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 37753994
Can I ask what you are doing to get that error?
0
 

Author Closing Comment

by:Seamus2626
ID: 37756346
Thanks.

I was able to plug that in

Seamus
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question