Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-20
6
Medium Priority
?
261 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 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

927 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