Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use the <code>On Error</code> statement that VBA supplies:</p> <pre><code>Sub TableTest On Error Goto TableTest_Error ' ...code that can fail... ' Exit Sub :TableTest_Error If Err.Number = 3061 Then Err.Clear() DoSomething() Else MsgBox Err.Description ' or whatever you find appropriate ' End If End Sub </code></pre> <p>Alternatively, you can switch off automatic error handling (e.g. breaking execution and displaying an error message) on a line-by-line basis:</p> <pre><code>Sub TableTest ' ... fail-safe code ... ' On Error Resume Next ' ...code that can fail... ' If Err.Number = 3061 Then Err.Clear() DoSomething() Else MsgBox Err.Description End If On Error Goto 0 ' ...mode fail-safe code... ' End Sub </code></pre> <p>There are these statements available:</p> <ul> <li><code>On Error Resume Next</code> switches off VBA-integrated error handling (message box etc.) completely, execution simply resumes on the next line. Be sure to check for an error very early after you've used that, as a dangling error can disrupt the normal execution flow. Clear the error as soon as you caught it to prevent that. </li> <li><code>On Error Goto &lt;Jump Label&gt;</code> resumes execution at a given label, primarily used for per-function error handlers that catch all sorts of errors.</li> <li><code>On Error Goto &lt;Line Number&gt;</code> resumes at a given line number. Stay away from that, it's not useful, even dangerous.</li> <li><code>On Error Goto 0</code> it's close cousin. Reinstates the VBA integrated error management (message box etc.)</li> </ul> <hr> <p><strong>EDIT</strong></p> <p>From the edited qestion, this is my proposal to solve your problem.</p> <pre><code>For Each FieldName In FieldNames ' assuming you have some looping construct here ' strsql3 = "SELECT " &amp; FieldName &amp; " FROM table" On Error Resume Next Set rs3 = CurrentDb.OpenRecordset(strsql3) If Err.Number = 3061 Then ' Do nothing. We dont care about this error ' Err.Clear Else MsgBox "Uncaught error number " &amp; Err.Number &amp; " (" &amp; Err.Description &amp; ")" Err.Clear End If On Error GoTo 0 Next FieldName </code></pre> <p>Be sure to clear the error <em>in any case</em> before you go on with a loop in the same Sub or Function. As I said, a dangling error causes code flow to become unexpected!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload