On Error Exit Function
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBA How to exit function on error? Not working. Access 2007 up vote 1 down vote favorite In Access 2007 My Error Trapping is set on Break on Unhandled Errors I want the code to stop at the line where an error occurs and exit functions instead of resuming to the next line of code. However it doesn't seem to be working for me. I purposely created an error at line 6 to see if it would exit the function after this line but it only prompts the error handler message and continues to resume to the next line after error occured. Here is my code: GoToBackend(): 'Go to current linked backend database Private Function GoToBackend() On Error GoTo BackendErrorHandler 'To update BEPath requires two sets of proc. 'Delete Exisiting RunQuery "DeleteBEEPath" 'Here is where I created error by miss spelling it 'Insert Into RunQuery "InsertBEPath" 'Prompt alert MsgBox "Front end tables succesfully linked. Access now needs to run the backend database to complete the linking process. Please ensure macros/vba are enabled if prompted.", 48 Hyperlink.GoHyperlink (Hyperlink.PrepHyperlink(GetBackendPath)) ExitFunction: Exit Function 'Why won't this exit the function? BackendErrorHandler: Dim Msg As String Msg = Err.Number & ": " & Err.Description MsgBox Msg Resume ExitFunction End Function RunQuery(): 'Run a given query name Private Function RunQuery(qName As String) On Error GoTo RunQueryErrorHandler DoCmd.SetWarnings False DoCmd.OpenQuery qName DoCmd.SetWarnings True ExitFunction: Exit Function RunQueryErrorHandler: Dim Msg As String Msg = Err.Number & ": " & Err.Description MsgBox Msg Resume ExitFunction End Function vba ms-access error-handling access-vba ms-access-2007 share|improve this question edited May 26 '15 at 16:13 shruti1810 2,3361725 asked May 22 '15 at 16:05 Jabberbyter 368 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted The error itself happens in your RunQuery function so the error is handled there. In there you say to display the message for th
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Samples Retired content We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Visual Basic Language Reference Statements F-P Statements F-P Statements On Error Statement On Error Statement On Error Statement For Each...Next Statement For...Next Statement http://stackoverflow.com/questions/30401288/vba-how-to-exit-function-on-error-not-working-access-2007 Function Statement Get Statement GoTo Statement If...Then...Else Statement Implements Statement Imports Statement (.NET Namespace and Type) Imports Statement (XML Namespace) Inherits Statement Interface Statement Mid Statement Module Statement Namespace Statement On Error Statement Operator Statement Option
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Samples Retired content We’re https://msdn.microsoft.com/en-us/library/t2at9t47.aspx sorry. The content you requested has been removed. You’ll be auto redirected in https://bytes.com/topic/access/answers/193185-how-exit-sub-error 1 second. Visual Basic Language Reference Statements A-E Statements A-E Statements Exit Statement Exit Statement Exit Statement AddHandler Statement Call Statement Class Statement Const Statement Continue Statement Declare Statement Delegate Statement Dim Statement Do...Loop Statement Else Statement End Statement End
your question and get tips & solutions from a community of 418,614 IT Pros & Developers. It's quick & easy. How to Exit Sub on Error? P: n/a deko Is there a shorthand way to Exit Sub On Error? This does not seem to work: On Error Exit Sub And I don't want to use: On Error GoTo 0 Must I use: GoTo Exit_Here? Nov 12 '05 #1 Post Reply Share this Question 4 Replies P: n/a Steve Jorgensen On Fri, 16 Jan 2004 00:34:25 GMT, "deko"