I'm using Access 2007. Most of the times when I import a file at my company, I get an error message because the item description is too long and it creates a table. I found a topic on how to delete the error tables in a macro, however I can't get it to work. Here's my code:
The error that I get says "Error Number 2950. Condition True, Arguments: DeleteImportErrTables()"
I'm a bit new at this, but I went to the "Data tools" tab on the ribbon. Clicked on Visual Basic, and then chose New - Module. I then copy and pasted the code above to the blank sheet.
Then went to Macro, and chose "RUN CODE" and told it the function name was DeleteImportErrTables ().
Code:
<code class="vb plain">Application.DisplayAlerts = </code><code class="vb keyword">False</code>
<code class="vb keyword">Function</code> <code class="vb plain">DeleteImportErrTables()</code>
<code class="vb keyword">Dim</code> <code class="vb plain">z </code><code class="vb keyword">As</code> <code class="vb keyword">Integer</code>
<code class="vb keyword">Dim</code> <code class="vb plain">db </code><code class="vb keyword">As</code> <code class="vb plain">DAO.Database</code>
<code class="vb keyword">Set</code> <code class="vb plain">db = CurrentDb</code>
<code class="vb keyword">For</code> <code class="vb plain">z = db.TableDefs.Count - 1 </code><code class="vb keyword">To</code> <code class="vb plain">0 </code><code class="vb keyword">Step</code> <code class="vb plain">-1</code>
<code class="vb keyword">If</code> <code class="vb plain">InStr(1, db.TableDefs(z).Name, </code><code class="vb string">"ImportError"</code><code class="vb plain">) > 0 </code><code class="vb keyword">Then</code>
<code class="vb plain">DoCmd.DeleteObject acTable, db.TableDefs(z).Name</code>
<code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb keyword">Next</code> <code class="vb plain">z</code>
<code class="vb keyword">End</code> <code class="vb keyword">Function</code>
The error that I get says "Error Number 2950. Condition True, Arguments: DeleteImportErrTables()"
I'm a bit new at this, but I went to the "Data tools" tab on the ribbon. Clicked on Visual Basic, and then chose New - Module. I then copy and pasted the code above to the blank sheet.
Then went to Macro, and chose "RUN CODE" and told it the function name was DeleteImportErrTables ().