listing fields

buggy2

Board Regular
Joined
Feb 28, 2003
Messages
69
I have listed the table names and the the field name for each of the tables out using msgbox(). I have also created a new table def and i was wondering how i could go about writing this data into the table i created in the form:

table1:field 1
table1:field 2
: :
: :
table1:Field n
table2:Field 1
: :
tablen:Field n

Here is the code i a using:

Sub list_fields()
Dim list_field As DAO.Field
Dim tbl As DAO.TableDef
Dim db As DAO.Database

Set db = CurrentDb
Set tbl = db.CreateTableDef("tbl List Fields")

For Each tbl In DBEngine.Workspaces(0).Databases(0).TableDefs
MsgBox (tbl.Name)

For Each list_field In DBEngine.Workspaces(0).Databases(0).TableDefs("tbl_value").Fields
MsgBox (loopy.Name)
Next

Next

End Sub

:rolleyes:
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try something like this:
Code:
Sub WriteTableFieldNamesToAnotherTable()
    Dim db As DAO.Database
    Dim fld As DAO.Field
    Dim tdf As DAO.TableDef
    Dim rst As DAO.Recordset
    
    Set db = CurrentDb
    
    Set tdf = db.CreateTableDef("tblListFields")
    With tdf
        .Fields.Append .CreateField("fldTableName", dbText)
        .Fields.Append .CreateField("fldFieldName", dbText)
    End With
    
    db.TableDefs.Append tdf
    Set rst = db.OpenRecordset(tdf.Name)
    Set tdf = Nothing
    
    For Each tdf In db.TableDefs
        For Each fld In tdf.Fields
            With rst
                .AddNew
                .Fields("fldTableName") = tdf.Name
                .Fields("fldFieldName") = fld.Name
                .Update
            End With
        Next fld
    Next tdf
            
    Set rst = Nothing
    
End Sub
HTH,

Russell
 
Upvote 0
listing fields, field data type, and description

How can this code be adapted to also list the field's data type and description?
 
Upvote 0
Thanks but I figured it out :)

Code:
Sub WriteTableFieldNamesToAnotherTable()
    Dim db As DAO.Database
    Dim fld As DAO.Field
    Dim tdf As DAO.TableDef
    Dim rst As DAO.Recordset
    Dim strTblName As String
    
    Set db = CurrentDb
    
        strTblName = "tblListFields"
        DoCmd.DeleteObject acTable, strTblName
        
    Set tdf = db.CreateTableDef("tblListFields")
    With tdf
        .Fields.Append .CreateField("fldTableName", dbText)
        .Fields.Append .CreateField("fldFieldName", dbText)
        .Fields.Append .CreateField("fldDescription", dbText)
    End With
    
    db.TableDefs.Append tdf
    Set rst = db.OpenRecordset(tdf.NAME)
    Set tdf = Nothing
    
    For Each tdf In db.TableDefs
    
    On Error GoTo Err_testing
        
        For Each fld In tdf.Fields
            With rst
                .AddNew
                .Fields("fldTableName") = tdf.NAME
                .Fields("fldFieldName") = fld.NAME
                .Fields("fldDescription") = fld.Properties("Description")
                .Update
            End With
        Next fld
    Next tdf

Exit_testing:
    Exit Sub
    
Err_testing:
    If Err.Number = 3270 Then
        '3270 is the error that is thrown for missing properties...
        Resume Next
    Else
        MsgBox "Error: " & Err.Number & ": " & Err.Description
        Resume Exit_testing
    End If
    
    Set rst = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top