473,385 Members | 1,333 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,385 software developers and data experts.

Iterate through table fields in an ADP?

Hi! Is it possible to iterate through table fields in an ADP? What
I'd like to do is:

Sub PrintTableFields()
Dim dbs As Object
Dim tbl As AccessObject
Dim fld As ????

Set dbs = Application.CurrentData
For Each tbl In dbs.AllTables
Debug.Print tbl .Name
For Each fld in tbl.????
Debug.Print " " & fld.Name
Next fld
Next tbl
I can't seem to get to the Fields collection of a table. Any help
would be greatly appreciated!
TIA,
DStark

Nov 13 '05 #1
3 3101
Make sure you have a reference to the library:
Microsoft ADO Ext. 2.x for DDL and Security

You can then examine the Columns in the Tables of the Catalog, like this:

Function ShowAllTables()
Dim cat As New ADOX.Catalog 'Root object of ADOX.
Dim tbl As ADOX.Table 'Each Table in Tables.
Dim col As ADOX.Column 'Each Column in the Table.

'Point the catalog to the current project's connection.
Set cat.ActiveConnection = CurrentProject.Connection

'Loop through the tables.
For Each tbl In cat.Tables
Debug.Print tbl.Name, tbl.Type
'Loop through the columns of the table.
For Each col In tbl.Columns
Debug.Print , col.Name, col.Type
Next
Debug.Print "--------------------------------"
Next

'Clean up
Set col = Nothing
Set tbl = Nothing
Set cat = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DStark" <st****@acm.org> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi! Is it possible to iterate through table fields in an ADP? What
I'd like to do is:

Sub PrintTableFields()
Dim dbs As Object
Dim tbl As AccessObject
Dim fld As ????

Set dbs = Application.CurrentData
For Each tbl In dbs.AllTables
Debug.Print tbl .Name
For Each fld in tbl.????
Debug.Print " " & fld.Name
Next fld
Next tbl
I can't seem to get to the Fields collection of a table. Any help
would be greatly appreciated!

Nov 13 '05 #2
Thanks, Allen!

That worked great. I assume there is no way to get field info from
AllTables collection. ADOX must be used.

DStark

Nov 13 '05 #3
You don't have to use ADOX...you can do this:

Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM INFORMATION_SCHEMA.COLUMNS",
CurrentProject.Connection

Do While Not rs.EOF
Debug.Print rs("TABLE_NAME"); vbTab; rs("COLUMN_NAME")
rs.MoveNext
Loop

Set rs = Nothing

Nov 13 '05 #4

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

Similar topics

4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
2
by: martin | last post by:
hi, I am using vb.net. I have wrote a data access class and one of my methods returns a dataset. I would like to iterate through this, although this is proving problematic for me. Can...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
0
by: news.zen.co.uk | last post by:
Hi Guys, Am wanting to iterate through a set of Mailmerge Fields within a MS-Word document using VB .NET. Here's a fragment of code that (should) do this! Dim WordDoc As Word.Document =...
1
by: JLuis | last post by:
Hi I'm consuming a WebService which is declared as String. When I read it I got a string, which is ok. But they tell me it also contains several fields (they built it in some Borland language),...
5
by: jaso | last post by:
Hi, If have a structure of a database record like this: struct record { char id; char title; ... }; Is there some way to find out how many member variables there is in the struct and then...
9
by: PeteCresswell | last post by:
I've got something called "Reference Rates". The idea is that on a given day, we have various rates of return for various entities. e.g. Libor 3-month return, Libor 6-month return, US Treasury...
4
by: nickvans | last post by:
Hello Access Gods... I am writing a bit of VBA code with the aim of allowing a user to easily add fields to a search form. I have a table with Category / Control_Name columns, which the VBA goes...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.