Solved

How to return the field type and field size of a table

Posted on 2014-10-20
6
245 Views
Last Modified: 2014-10-20
I am trying to determine the data type and size of fields in a specified table.
I am using the following code to return the list of fields in the table and write the information to table "TableFieldNames"

        Dim fld As DAO.Field
        Dim db As DAO.Database
        Dim rs2 As DAO.Recordset

        Set db = OpenDatabase(txtdatabasename)    
        Set rs2 = Currentdb.OpenRecordset("TableFieldNames")
        Currentdb.Execute ("DELETE TableFieldNames.* FROM TableFieldNames")

        For Each fld In db.TableDefs(cmbTable).Fields
              rs2.AddNew
              rs2!NamofTable = cmbTable
              rs2!NameOfField = fld.Name
              rs2!TypeofField = ??????????
              rs2!SizeofField = ?????????
              rs2.Update
        Next fld
        rs2.close

In rs2!TypeofField I want to put the specified data type for the field (Text, Number, Date/Time, etc.)
If the data type is Text or Number I want to put the specified field size in rs2!Sizeoffield (255, integer, double, etc.)
Is this doable?
0
Comment
Question by:dsoderstrom
  • 3
  • 3
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40392510
use

              rs2!TypeofField = fld.type
              rs2!SizeofField = fld.size
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40392521
see this link to get the field description and other attributes

http://allenbrowne.com/func-06.html
0
 

Author Comment

by:dsoderstrom
ID: 40392538
I tried using fld.type and fld.size but what I get is numbers.
For example, a field that has a data type of "Text" returns a "10" for the field type.  The field size returns correctly.
A field with a data type of "Number" and a field size of "Double" returns "7" for the datatype and "8" for the field size.
Is there a way to return the actual data type and size as it shows in the field properties of the table?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40392548
look at my second post..
0
 

Author Comment

by:dsoderstrom
ID: 40392554
Yep, sorry.  Responded to your first one before I got the second one.
Just trying it now.
0
 

Author Closing Comment

by:dsoderstrom
ID: 40392570
this was just what I needed.
Thanks once again.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now