473,508 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get table names from MSAccess Datasource

Hello all,

I have a vb6 (not .NET) program using MS Access as the backend. As part of
an import form, I need to allow the user to select the table containing the
data to be imported. How can I populate a combo with this information?
Then, once this value is selected, how can I populate other combos with the
column names of the selected table?
Thanks,

Steven Smith

Apr 17 '06 #1
4 23894
Steven Smith wrote:
I have a vb6 (not .NET) program using MS Access as the backend. As
part of an import form, I need to allow the user to select the table
containing the data to be imported. How can I populate a combo with
this information? Then, once this value is selected, how can I
populate other combos with the column names of the selected table?


Iterate the TableDefs collection looking at each item's Name property to
offer a choice of tables. And, within each TableDef, you can loop the
Fields collection.
--
Apr 17 '06 #2
Thanks Karl... I would've preferred ADO or SQL, but since it's only for one
query in my program, this'll work just fine!
"Karl E. Peterson" <ka**@mvps.org> wrote in news:e210ej$3im$1
@emma.aioe.org:
Steven Smith wrote:
I have a vb6 (not .NET) program using MS Access as the backend. As
part of an import form, I need to allow the user to select the table
containing the data to be imported. How can I populate a combo with
this information? Then, once this value is selected, how can I
populate other combos with the column names of the selected table?


Iterate the TableDefs collection looking at each item's Name property to
offer a choice of tables. And, within each TableDef, you can loop the
Fields collection.


Apr 18 '06 #3

"Steven Smith" <sl****@webbox.com> wrote in message
news:Tu*****************@twister.nyroc.rr.com...
Thanks Karl... I would've preferred ADO or SQL, but since it's only for one query in my program, this'll work just fine!
"Karl E. Peterson" <ka**@mvps.org> wrote in news:e210ej$3im$1
@emma.aioe.org:
Steven Smith wrote:
I have a vb6 (not .NET) program using MS Access as the backend. As
part of an import form, I need to allow the user to select the table
containing the data to be imported. How can I populate a combo with
this information? Then, once this value is selected, how can I
populate other combos with the column names of the selected table?


Iterate the TableDefs collection looking at each item's Name property to
offer a choice of tables. And, within each TableDef, you can loop the
Fields collection.


Sub ListTablesADO() Dim cnn As ADODB.Connection Set cnn = New
ADODB.Connection Dim rsTables As ADODB.Recordset Dim rsColumns As
ADODB.Recordset 'Open connection you want To get database objects
cnn.Provider = "MSDASQL" ' whatever needed... cnn.Open
"DSN=...;Database=...;", "UID", "PWD" 'Get all database tables. Set
rsTables = cnn.OpenSchema(adSchemaTables) Do While Not rsTables.EOF
'Get all table columns. Set rsColumns = cnn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, "" & rsTables("TABLE_NAME"))) Do While Not
rsColumns.EOF Debug.Print rsTables("TABLE_NAME") & ", " & _
rsColumns("COLUMN_NAME") rsColumns.MoveNext Loop
rsTables.MoveNext LoopEnd SubSub ListTablesADOX() Dim cnn As
ADODB.Connection Set cnn = New ADODB.Connection 'Open connection you
want To get database objects cnn.Provider = "MSDASQL" ' whatever you
need... cnn.Open "DSN=...;Database=...;", "UID", "PWD" 'Create catalog
object Dim Catalog As New ADOX.Catalog Set Catalog.ActiveConnection = cnn
'List tables And columns Dim tbl As ADOX.Table Dim col As ADOX.Column For
Each tbl In Catalog.Tables Debug.Print tbl.Name For Each col In
tbl.Columns Debug.Print col.Name Next NextEnd Sub
Apr 18 '06 #4

"Ralph" <nt*************@yahoo.com> wrote in message
news:R8******************************@arkansas.net ...

"Steven Smith" <sl****@webbox.com> wrote in message
news:Tu*****************@twister.nyroc.rr.com...
Thanks Karl... I would've preferred ADO or SQL, but since it's only for one
query in my program, this'll work just fine!
"Karl E. Peterson" <ka**@mvps.org> wrote in news:e210ej$3im$1
@emma.aioe.org:
Steven Smith wrote:
> I have a vb6 (not .NET) program using MS Access as the backend. As
> part of an import form, I need to allow the user to select the table
> containing the data to be imported. How can I populate a combo with
> this information? Then, once this value is selected, how can I
> populate other combos with the column names of the selected table?

Iterate the TableDefs collection looking at each item's Name property to offer a choice of tables. And, within each TableDef, you can loop the
Fields collection.


Sub ListTablesADO() Dim cnn As ADODB.Connection Set cnn = New
ADODB.Connection Dim rsTables As ADODB.Recordset Dim rsColumns As
ADODB.Recordset 'Open connection you want To get database objects
cnn.Provider = "MSDASQL" ' whatever needed... cnn.Open
"DSN=...;Database=...;", "UID", "PWD" 'Get all database tables. Set
rsTables = cnn.OpenSchema(adSchemaTables) Do While Not rsTables.EOF
'Get all table columns. Set rsColumns = cnn.OpenSchema(adSchemaColumns,

_ Array(Empty, Empty, "" & rsTables("TABLE_NAME"))) Do While Not
rsColumns.EOF Debug.Print rsTables("TABLE_NAME") & ", " & _
rsColumns("COLUMN_NAME") rsColumns.MoveNext Loop
rsTables.MoveNext LoopEnd SubSub ListTablesADOX() Dim cnn As
ADODB.Connection Set cnn = New ADODB.Connection 'Open connection you
want To get database objects cnn.Provider = "MSDASQL" ' whatever you
need... cnn.Open "DSN=...;Database=...;", "UID", "PWD" 'Create catalog
object Dim Catalog As New ADOX.Catalog Set Catalog.ActiveConnection = cnn 'List tables And columns Dim tbl As ADOX.Table Dim col As ADOX.Column For Each tbl In Catalog.Tables Debug.Print tbl.Name For Each col In
tbl.Columns Debug.Print col.Name Next NextEnd Sub


Sorry, don't know what happened to the paste...

Sub ListTablesADO()
Dim cnn As ADODB.Connection:
Set cnn = New ADODB.Connection
Dim rsTables As ADODB.Recordset
Dim rsColumns As ADODB.Recordset
'Open connection you want To get database objects
cnn.Provider = "MSDASQL" ' whatever needed...
cnn.Open "DSN=...;Database=...;", "UID", "PWD"
'Get all database tables. Set
rsTables = cnn.OpenSchema(adSchemaTables)
Do While Not rsTables.EOF
'Get all table columns.
Set rsColumns = cnn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, "" & rsTables("TABLE_NAME")))
Do While Not rsColumns.EOF
Debug.Print rsTables("TABLE_NAME") & ", " & _
rsColumns("COLUMN_NAME")
rsColumns.MoveNext
Loop
rsTables.MoveNext
Loop
End Sub

Sub ListTablesADOX()
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
'Open connection you want To get database objects
cnn.Provider = "MSDASQL" ' whatever you need...
cnn.Open "DSN=...;Database=...;", "UID", "PWD"
'Create catalog object
Dim Catalog As New ADOX.Catalog
Set Catalog.ActiveConnection = cnn
'List tables And columns
Dim tbl As ADOX.Table
Dim col As ADOX.Column
For Each tbl In Catalog.Tables
Debug.Print tbl.Name
For Each col In tbl.Columns
Debug.Print col.Name
Next
Next
End Sub

Apr 19 '06 #5

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

Similar topics

1
6177
by: X | last post by:
Howdy: To follow up on a problem with MS Access (2000) and Oracle 9i (9.2.0.x) - History: I am trying to import tables from my Oracle 9i database on RedHat Linux 7.2 to MS Access (2000) on...
0
984
by: Paul | last post by:
Hi I have a problem with the DataGrid Datasource. The issue is this, setting the grid DataSource to Table1, which is done when the page loads and then changing the datasource to a different...
22
4203
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty...
4
1436
by: Mel | last post by:
Hi, I created a form that would search a record from a table and showed the details in datagrid. I have another button that would insert the records showed in the datagrid to another table..How...
4
1330
by: robboll | last post by:
Please excuse my ignorance, but I am trying to teach myself .Net without a lot of help. At this point I have created a page with a few text boxes and combo boxes that I am using as an example. ...
11
6641
by: Kay | last post by:
Hi all, I have populated a dataset with several tables, say - Roster, Agent and few more . The dataset is used to populated a listview with some shift info.. I think I'm sucessfully created a...
6
2448
by: Steven Smith | last post by:
Hello all, I have a vb6 (not .NET) program using MS Access as the backend. As part of an import form, I need to allow the user to select the table containing the data to be imported. How can I...
4
3856
by: Gregory Gadow | last post by:
If there is a more appropriate forum, please let me know and I will post there. Our field reps can go on to our website and select from several sets of data to create the address we then provide...
3
1995
by: Icemokka | last post by:
Hi, I've got a table in MsAccess with 100+ fields. If I fill a tabletable with this table , change some values , get the update-command via commandbuilder , the update fails. This because the...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
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
7499
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
5631
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,...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.