Need to loop through

Geoff Codd

Registered User.
Local time
Today, 17:41
Joined
Mar 6, 2002
Messages
190
I am using the following code to delete a group of temporary tables, when a particular form is closed, the problem I am having is that not all the tables will exist. When a table doesn't exist the code stops running and the remaing tables are not deleted. I need a way to loop through until all tables are deleted.

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click

DoCmd.DeleteObject acTable, "tblDevolution_Electricity_(Data_Table)"
DoCmd.DeleteObject acTable, "tblDevolution_Electricity_(Running_Sum)_Present"
DoCmd.DeleteObject acTable, "tblDevolution_Electricity_(Running_Sum)_Previous"
DoCmd.DeleteObject acTable, "tblEnergy_Management_Statistics_(Temp)"

DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
Resume Exit_Close_Form_Click


Thanks in advance
Geoff
 
Geoff Codd said:
I am using the following code to delete a group of temporary tables, when a particular form is closed, the problem I am having is that not all the tables will exist. When a table doesn't exist the code stops running and the remaing tables are not deleted. I need a way to loop through until all tables are deleted.

Even easier; change the type of error handling

Code:
Private Sub Close_Form_Click()
    On Error Resume Next 

    With DoCmd
        .DeleteObject acTable, "tblDevolution_Electricity_(Data_Table)"
        .DeleteObject acTable, "tblDevolution_Electricity_(Running_Sum)_Present"
        .DeleteObject acTable, "tblDevolution_Electricity_(Running_Sum)_Previous"
        .DeleteObject acTable, "tblEnergy_Management_Statistics_(Temp)"
    End With

    DoCmd.Close acForm, Me.Name ' close the form

End Sub
 
Thanks very much, works a treat

Geoff
 

Users who are viewing this thread

Back
Top Bottom