473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How can I get all table names from MS Access

I'm using VB and I need to get all table names in database. How can I do
that?

Thank you.
Nov 12 '05 #1
4 5810
Mlaky wrote:
I'm using VB and I need to get all table names in database. How can I do
that?

Thank you.

select name from msysobjects where type=1

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #2
Public Function GetTableNamesDAO(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.OpenDatabase(strDatabase)
ReDim straTableNames(db.TableDefs.Count - 1)
For lngLoop = 0 To db.TableDefs.Count - 1
straTableNames(lngLoop) = db.TableDefs(lngLoop).Name
Next lngLoop
db.Close
GetTableNamesDAO = straTableNames

End Function

Public Sub TestGetTableNamesDAO()

'used for testing within Access - will need modification for VB

Dim straTableNames() As String
Dim lngLoop As Long

straTableNames = GetTableNamesDAO(CurrentProject.FullName)
For lngLoop = LBound(straTableNames) To UBound(straTableNames)
Debug.Print straTableNames(lngLoop)
Next lngLoop

End Sub

Public Function GetTableNamesADOX(ByVal TheConnection As ADODB.Connection)
As String()

'requires references to ADODB and ADOX object libraries

Dim straTableNames() As String
Dim cat As ADOX.Catalog
Dim lngLoop As Long
Dim boolOpenedConnection As Boolean

If TheConnection.State <> adStateOpen Then
TheConnection.Open
boolOpenedConnection = True
End If
Set cat = New ADOX.Catalog
cat.ActiveConnection = TheConnection
ReDim straTableNames(cat.Tables.Count - 1)
For lngLoop = 0 To cat.Tables.Count - 1
straTableNames(lngLoop) = cat.Tables(lngLoop).Name
Next lngLoop
GetTableNamesADOX = straTableNames
If boolOpenedConnection Then
TheConnection.Close
End If

End Function

Public Function TestGetTableNamesADOX()

'used for testing within Access - will need modification for VB

Dim straTableNames() As String
Dim lngLoop As Long

straTableNames = GetTableNamesADOX(CurrentProject.Connection)
For lngLoop = LBound(straTableNames) To UBound(straTableNames)
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.

Nov 12 '05 #3
I can't do that. I've got following message:

Error: Record(s) cannot be read; no read permission on 'msysobjects'.
select name from msysobjects where type=1

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #4
"Mlaky" <ml************@email.htnet.hr> wrote in news:c0sto0$knj$1
@ls219.htnet.hr:
I can't do that. I've got following message:
Error: Record(s) cannot be read; no read permission on 'msysobjects'.
select name from msysobjects where type=1
--
Bas Cost Budde


For Version >= 2K:

Public Function GetTableNames() As ADODB.Recordset
Set GetTableNames = CurrentProject.Connection.OpenSchema
(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
End Function

Sub test()
Debug.Print GetTableNames.GetString(, , ",", , vbTab)
End Sub
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am...
3
by: Tom | last post by:
Data is collected over time in an Excel worksheet with 20 columns. The Excel worksheet starts out as a copy of a template as is filled in as data is collected. Eventually the worksheet file is...
6
by: Bernd Koehler | last post by:
Hi: I am a EE prof currently teaching an IT course. One the assignments students recently completed was designing a small MS Access Database. I have two submissions that are remarkably...
5
by: premmehrotra | last post by:
I am using Microsoft Access 2000 and Oracle 9.2.0.5 on Windows 2000. When I export a table from Access to Oracle using ODBC I get error: ORA 972 identifier too long I think the error is because...
6
by: davegb | last post by:
I'm trying to create a self-join table to show the relationship between employee and supervisor. In another thread, I was advised to create a SupervisorID in the employee table, a separate...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
3
by: David C. Barber | last post by:
Using SQL Server 2000 and moving to a new computer. We did a full backup of the existing database to tape, brought up the new computer with a clean install using the same server name and IP...
11
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I...
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
2
by: myemail.an | last post by:
Hi all, I need to export a table from Ms Sql to Access. However, dts import/ export gives me an error because the field names are too long. Is there a quick way to trim the names of all fields...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.