Public Function GetTableNamesDA O(ByVal strDatabase As String) As String()
'requires reference to DAO object library
Dim straTableNames( ) As String
Dim db As DAO.Database
Dim lngLoop As Long
Set db = DBEngine.OpenDa tabase(strDatab ase)
ReDim straTableNames( db.TableDefs.Co unt - 1)
For lngLoop = 0 To db.TableDefs.Co unt - 1
straTableNames( lngLoop) = db.TableDefs(ln gLoop).Name
Next lngLoop
db.Close
GetTableNamesDA O = straTableNames
End Function
Public Sub TestGetTableNam esDAO()
'used for testing within Access - will need modification for VB
Dim straTableNames( ) As String
Dim lngLoop As Long
straTableNames = GetTableNamesDA O(CurrentProjec t.FullName)
For lngLoop = LBound(straTabl eNames) To UBound(straTabl eNames)
Debug.Print straTableNames( lngLoop)
Next lngLoop
End Sub
Public Function GetTableNamesAD OX(ByVal TheConnection As ADODB.Connectio n)
As String()
'requires references to ADODB and ADOX object libraries
Dim straTableNames( ) As String
Dim cat As ADOX.Catalog
Dim lngLoop As Long
Dim boolOpenedConne ction As Boolean
If TheConnection.S tate <> adStateOpen Then
TheConnection.O pen
boolOpenedConne ction = True
End If
Set cat = New ADOX.Catalog
cat.ActiveConne ction = TheConnection
ReDim straTableNames( cat.Tables.Coun t - 1)
For lngLoop = 0 To cat.Tables.Coun t - 1
straTableNames( lngLoop) = cat.Tables(lngL oop).Name
Next lngLoop
GetTableNamesAD OX = straTableNames
If boolOpenedConne ction Then
TheConnection.C lose
End If
End Function
Public Function TestGetTableNam esADOX()
'used for testing within Access - will need modification for VB
Dim straTableNames( ) As String
Dim lngLoop As Long
straTableNames = GetTableNamesAD OX(CurrentProje ct.Connection)
For lngLoop = LBound(straTabl eNames) To UBound(straTabl eNames)
Debug.Print straTableNames( lngLoop)
Next lngLoop
End Function
--
Brendan Reynolds
"Mlaky" <ml************ @email.htnet.hr > wrote in message
news:c0******** **@ls219.htnet. hr...
I'm using VB and I need to get all table names in database. How can I do
that?
Thank you.