473,795 Members | 3,441 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 23909
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.or g> 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******** *********@twist er.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.or g> 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.Connectio n Set cnn = New
ADODB.Connectio n 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=...;Databa se=...;", "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("COLU MN_NAME") rsColumns.MoveN ext Loop
rsTables.MoveNe xt LoopEnd SubSub ListTablesADOX( ) Dim cnn As
ADODB.Connectio n Set cnn = New ADODB.Connectio n 'Open connection you
want To get database objects cnn.Provider = "MSDASQL" ' whatever you
need... cnn.Open "DSN=...;Databa se=...;", "UID", "PWD" 'Create catalog
object Dim Catalog As New ADOX.Catalog Set Catalog.ActiveC onnection = 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******** *************** *******@arkansa s.net...

"Steven Smith" <sl****@webbox. com> wrote in message
news:Tu******** *********@twist er.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.or g> 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.Connectio n Set cnn = New
ADODB.Connectio n 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=...;Databa se=...;", "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("COLU MN_NAME") rsColumns.MoveN ext Loop
rsTables.MoveNe xt LoopEnd SubSub ListTablesADOX( ) Dim cnn As
ADODB.Connectio n Set cnn = New ADODB.Connectio n 'Open connection you
want To get database objects cnn.Provider = "MSDASQL" ' whatever you
need... cnn.Open "DSN=...;Databa se=...;", "UID", "PWD" 'Create catalog
object Dim Catalog As New ADOX.Catalog Set Catalog.ActiveC onnection = 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.Connectio n:
Set cnn = New ADODB.Connectio n
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=...;Databa se=...;", "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("COLU MN_NAME")
rsColumns.MoveN ext
Loop
rsTables.MoveNe xt
Loop
End Sub

Sub ListTablesADOX( )
Dim cnn As ADODB.Connectio n
Set cnn = New ADODB.Connectio n
'Open connection you want To get database objects
cnn.Provider = "MSDASQL" ' whatever you need...
cnn.Open "DSN=...;Databa se=...;", "UID", "PWD"
'Create catalog object
Dim Catalog As New ADOX.Catalog
Set Catalog.ActiveC onnection = 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
6201
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 NT. I managed to turn on logging / debugging for ODBC connections and I got a few messages that I am unfamiliar with.
0
1011
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 one causes issues. Now when the user clicks on a Search button, it changes the DataSource to a different table using a DataTable.DefaultView and here lies the
22
4236
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 SQL table? Is there a short way like the FILL method to get data into the dataset or do I have to read each datarow in the table and write it one at the time to the
4
1449
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 will I do this?
4
1344
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. The page displays nicely with the Requestor, DivMgr, ChgType, Description fields. What I would like to do at this point is create a Save button (at bottom ref: Button1_Click) that, when clicked, inserts the data to the table.
11
6683
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 relationship in the dataset. In the Roster table there's an "AgentKey" which can be linked to the Agent table. What I'm tryting to do is, while I'm looping thru the dataset, I want to show the Name of an Agent in the listview from the Agent...
6
2471
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 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,
4
3866
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 to their clients in company correspondence. Using just name as an example, one rep might have a choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy Smith" while a different rep might have only "Elizabeth Jones" and "Liz Jones."...
3
2005
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 commandbuilder adds a where clause that contains all the fields in the datatable ( to check whether the record has been changed since the fill ). Because MSAccess does not allow more then 99 fields in the where clause, the update fails offcourse.
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10437
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
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 we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.