Emtry Table Error Trapping

purceld2

Registered User.
Local time
Today, 16:20
Joined
Dec 4, 2008
Messages
79
I am new to coding and have an issue that when the code below runs and finds the table empty it errors and falls over.

How could I amend the code to accept this condition and continue running the remaining code

Would it be best to test the presence of data in the table before calling the function or use error trapping?

Thanks you in advance for your advice

Des

Code:
Function Clr_Results()
Set activedb = DBEngine.Workspaces(0).Databases(0)
Set RES = activedb.OpenRecordset("Results")
RES.MoveFirst
Do
RES.Delete
RES.MoveNext
Loop Until RES.EOF
RES.Close
End Function
 
I would get rid of the whole recordset and just use a delete query

Code:
Dim strSQL As String

strSQL = "Delete * FROM Results"

CurrentDb.Execute strSQL, dbFailOnError

Simpler, faster and more efficient.
 
Re: Empty Table Error Trapping

Thanks bob for your reply

Can I ask if your solution would over come the problem of the code falling over if the table is already empty. Would it be able to handle this and allow the code to continue running

Regards

Des
 
Re: Empty Table Error Trapping

Thanks bob for your reply

Can I ask if your solution would over come the problem of the code falling over if the table is already empty. Would it be able to handle this and allow the code to continue running

Regards

Des


Yep, it isn't reliant on anything being in the table.
 

Users who are viewing this thread

Back
Top Bottom