title: VBA On Error Exit Calling Function
body: <p>I have a simple excel function that connects to a db and retrieves some data and populates a worksheet. The function calls another function to make the db connection and return the query results. How do I exit the calling function if there is an error connecting to the database? This is what my function looks like that connects to the DB. If there is an error connecting to the DB, the messagebox is displayed but then processing resumes in the calling function and then I get an ugly "END or DEBUG" message box...which I am trying to avoid.</p>
  
  <pre><code>Public Function QueryDB(sQuery As String)
  
  On Error GoTo ErrorHandler
  
  ... Connect to database and get data
  
  ErrorHandler:
  ... Display a messagebox telling the user there is an error
  
  'Resume Next
  Exit Function
  
  End Function
  </code></pre>