Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping

Status
Not open for further replies.
May 5, 2000
168
US
I have a macro that runs an update procedure based on an import of data from an accouning database.<br><br>The first step of the procedure deletes some existing tables before importing the new ones.&nbsp;&nbsp;I want the macro to make sure the table exists before it deletes it (Otherwise the macro halts).&nbsp;&nbsp;&nbsp;If the table doesn't exist it skips that table and goes on to the next.<br><br>Also, as the macro procedes the database becomes quite large (800 -900 megs) and needs to be compacted.&nbsp;&nbsp;I want this to be done automatically in the macro. <br><br>Any suggestions?
 
This is one of the reasons macros are not good when you begin to encounter errors. Macros do not allow for error handling, only code does. <br><br>I would suggest using code to do this. As far as the object exists, there is a answer to this question in the FAQ. There is also another post regarding compacting automatically that has been in this forum in the last day or two.<br><br>For example, put this in a module:<br><br>-----<br><br>Public Sub RunMyProcedure()<br>&nbsp;&nbsp;&nbsp;' See the FAQ for the ObjectExists Function, Do this for all the tables you wish to delete.<br>&nbsp;&nbsp;&nbsp;If ObjectExists(acTable, &quot;Table1&quot;) Then Docmd.DeleteObject acTable, &quot;Table1&quot;<br>&nbsp;&nbsp;&nbsp;If ObjectExists(acTable, &quot;Table2&quot;) Then Docmd.DeleteObject acTable, &quot;Table2&quot;<br><br>&nbsp;&nbsp;&nbsp;' Do your compacting code here<br><br>End Sub<br><br>-----<br><br>If you want to run it manually, simply open the Debug window (ctrl+G), and type Call RunMyProcedure. Or attach the &quot;Call RunMyProcedure&quot; line to say a button click event. <br><br>HTH <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top