Another little problem in SQL!!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I know I'm pushing it with two problems in the same day! I want to run a
delete query in SQL from a VB module. How do I tell it not to run the delete
query if the table is empty? Very many thanks.
 
It should not matter whether the table is empty or not when you run the
delete query. If there is nothing to delete, nothing happens. You can check
to see if there are any records in the table, but I would question whether
any processing time is saved by doing so. Here is how you can do it:

With CurrentDb
If .TableDefs("MyTableName").RecordCount > 0 Then
.Execute("DELETE * FROM MyTableName;")
End If
End With
 
Thanks for that. In fact if I try to run a delete sql statement from within
VB and the table is empty it comes back with an error message. But now I can
get around that. Thanks again!
 
Back
Top