Solved

Error message

Posted on 2012-03-22
5
215 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
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:DaFranker
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:
DaFranker earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now