Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Table and field names using VBA 1

Status
Not open for further replies.

Jorgandr

Programmer
May 10, 2002
58
0
0
US
How would you get field names using VBA? I want to do this so that I can create a custom query builder that end users can use via a form. i have the table part of it.

Function ShowTables()
Dim mytables As TableDefs
Dim currenttable As TableDef
Dim currentfields As Fields

Set mytables = CurrentDb.TableDefs

For Each currenttable In mytables
If Left(currenttable.Name, 3) = "Tbl" Then
MsgBox currenttable.Name
End If
Next currenttable


End Function

Now I'm just wondering how to get the field names for these tables. Any help would be appreciated. Thanks
 
Code:
Function ShowTables()
    Dim mytables As TableDefs
    Dim currenttable As TableDef
    Dim currentfield As Field
    
    Set mytables = CurrentDb.TableDefs
       
    For Each currenttable In mytables
        If Left(currenttable.Name, 3) = "Tbl" Then
            Debug.Print currenttable.Name
            For Each currentfield in currenttable.Fields
               Debug.Print currentfield.Name
            Next currentfield
        End If
    Next currenttable

End Function
If you examine other properties of the field object, you will find you can obtain the size, data type, whether it is required or not, the description etc.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top