Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    tableDefs (2002)

    I have the following function:

    Function GetFieldNames(table As String) As Integer

    Dim db As DAO.Database
    Dim tdfTable As DAO.TableDef
    Dim fldField As DAO.Field

    Set db = CurrentDb()
    Set tdfTable = db.TableDefs(table)

    For Each fldField In tdfTable.Fields

    Debug.Print fldField.Name

    Next fldField

    End Function

    How do I get the data type and field size to print? I need a create table script to recreate the table structure in a SQL db. Any help would be appreciated.

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: tableDefs (2002)

    This code will print out all the properties of each field

    For Each prp in fldField.Properties
    if prp.Name <> "" then
    debug.print prp.Name & " =" & prp
    end if
    Next prp


    The data type and size are just two of the field's properies.

    The code above is copied from Helene Feddema's book: DAO Object Model
    Regards
    John



  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: tableDefs (2002)

    Try this version:

    Function GetFieldNames(table As String) As Integer
    Dim db As DAO.Database
    Dim tdfTable As DAO.TableDef
    Dim fldField As DAO.Field
    Dim strType As String

    Set db = CurrentDb
    Set tdfTable = db.TableDefs(table)

    For Each fldField In tdfTable.Fields
    Select Case fldField.Type
    Case dbBoolean
    strType = "Boolean"
    Case dbByte
    strType = "Byte"
    Case dbCurrency
    strType = "Currency"
    Case dbDate
    strType = "Date"
    Case dbDouble
    strType = "Double"
    Case dbInteger
    strType = "Integer"
    Case dbLong
    strType = "Long"
    Case dbLongBinary
    strType = "OLE"
    Case dbMemo
    strType = "Memo"
    Case dbSingle
    strType = "Single"
    Case dbText
    strType = "Text"
    Case Else
    strType = "Other type"
    End Select
    Debug.Print fldField.Name, strType, fldField.Size
    Next fldField

    Set fldField = Nothing
    Set tdfTable = Nothing
    Set db = Nothing
    End Function

  4. #4
    2 Star Lounger
    Join Date
    Feb 2003
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: tableDefs (2002)

    Thanks Hans...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •