×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to extract Access table schema with decimal places on numeric fields?

How to extract Access table schema with decimal places on numeric fields?

How to extract Access table schema with decimal places on numeric fields?

(OP)
In a VBA module within an Access database I am trying to create a query which needs the schema information for a table. I can get the field names, type and size but cannot get the decimal places for the various numeric types. Anyone have a clue how to get the field properties as seen in design mode?

Following are a couple of failed tries which do not give me the decimal places for the various fields.

CODE

Private Function GetSchema1(tcTable As String)
Dim oDatabase As Database, oTabledef As TableDef
Set oDatabase = CurrentDb()
Set oTabledef = oDatabase.TableDefs(tcTable)

For Each oField In oTabledef.Fields
   a = 1
Next oField
End Function 

CODE

Private Function CreateSQL(tcTable As String)
Dim cSQL As String, oDatabase As Database, oRecordset As Recordset
cSQL = "SELECT * FROM " + tcTable + " WHERE 1=0"
Set oDatabase = CurrentDb()
Set oRecordset = oDatabase.OpenRecordset(cSQL, dbOpenDynaset)
Dim iFields As Integer, oField As Object, cFieldName As String
For iFields = 0 To oRecordset.Fields.Count - 1
   Set oField = oRecordset.Fields(iFields)
   With oField
   cFieldName = .Name
   Select Case .Type
   Case Is = dbBigInt
   End With
Next iFields
End Function 
TIA, Mark

RE: How to extract Access table schema with decimal places on numeric fields?

Your code needs...

CODE

For iFields = 0 To oRecordset.Fields.Count - 1
   Set oField = oRecordset.Fields(iFields)
   With oField
      cFieldName = .Name
      Select Case .Type
         Case Is = dbBigInt
      End Select
   End With
Next iFields 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: How to extract Access table schema with decimal places on numeric fields?

Some field properties such as format are not available until after you have set them.

You can do a simple test to find properties with code like the following which is not meant for production and will error out if allowed.

CODE --> vba

Sub PrintProperties(strTable As String, strField As String)
    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Dim fd As DAO.Field
    Dim intProp As Integer
    On Error Resume Next
    Set db = CurrentDb
    Set td = db.TableDefs(strTable)
    Set fd = td.Fields(strField)
    For intProp = 1 To fd.Properties.Count
        Debug.Print fd.Properties(intProp).Name, fd.Properties(intProp).Value
    Next
    Set fd = Nothing
    Set td = Nothing
    Set db = Nothing
End Sub 

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close