Sub DeleteRecordsFromTables()
Dim tdf As TableDef
Dim strSQL As String
Dim db As DAO.Database
Set db = CurrentDb
For Each tdf In db.TableDefs
If Left(tdf.Name, 3) = "tbl" Then
strSQL = "DELETE * FROM " & tdf.Name
Debug.Print strSQL
db.Execute strSQL
End If
Next
End Sub
For Each tdf In db.TableDefs
x = DCount("*", "[" + tdf.Name + "]")
If x = 0 Then
Debug.Print(tdfName)
End If
Next
Because it makes perfect sense to have some sort of naming convention for objects. Some use t to denote a table. It's a heck of a lot better than having 3 objects named "OrderDetails" when one is a table, one is a query and the third is a form.I have no idea why that is so popular with Access.
It was an example?That particular query also relies on the convention of having all table names start with tbl. I have no idea why that is so popular with Access. But the example is on the right track. I think if you print all the table names some of them start with sys or ~ and those would all be system tables. All the rest would be ordinary tables. At any rate, you could turn that into a select count():
VBA Code:For Each tdf In db.TableDefs x = DCount("*", "[" + tdf.Name + "]") If x = 0 Then Debug.Print(tdfName) End If Next
Sub tblCount()
Dim tdf As DAO.TableDef
Dim db As DAO.Database
Set db = CurrentDb()
For Each tdf In db.TableDefs
Debug.Print tdf.Name & " " & tdf.RecordCount
Next
End Sub
Because it makes perfect sense to have some sort of naming convention for objects. Some use t to denote a table. It's a heck of a lot better than having 3 objects named "OrderDetails" when one is a table, one is a query and the third is a form.
' ----------------------------------------------------------------
' Procedure Name: IsLinked
' Purpose: To check whether a given Table is Linked or not
'Non-linked tables have a type of 1,
'tables linked using ODBC have a type of 4
'other linked tables(Access) have a type of 6
' Procedure Kind: Function
' Procedure Access: Public
' Parameter TableName (String): The name of the table to check
' Return Type: Boolean
' Author: Jack
' Date: 30-Mar-21
' ----------------------------------------------------------------
Function IsLinked(TableName As String) As Boolean
10 IsLinked = Nz(DLookup("Type", "MSysObjects", _
"Name = '" & TableName & "'"), 0) <> 1
End Function