You are currently offline, waiting for your internet to reconnect

ACC2000: How to Use Schema.ini to Access Text Data

This article was previously published under Q210073
This article has been archived. It is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

SUMMARY
This article describes how to use a Schema.ini file and Data Access Objects(DAO) to programmatically open or link to a text file. A Schema.inifile contains the specifics on how data is formatted in a particular textfile and is used by the Text ISAM driver to read and manipulate data.
MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To create a Schema.ini file and a fixed-width text file that you can use inthe Example section later in this article, follow these steps:
  1. Start a text editor, such as Notepad.
  2. In a new text file, type the following text and save the file as Contacts.txt:
    NOTE: Because Contacts.txt is a fixed-width text file, the spacing in the file you create must be exactly as shown.
       First NameLast NameHireDate   Nancy     Davolio  10-22-91   Robert    King     10-23-91					
  3. In another new text file, type the following text and save the file as Schema.ini:
    [Contacts.txt]
    ColNameHeader=True
    Format=FixedLength
    MaxScanRows=0
    CharacterSet=OEM
    Col1="First Name" Char Width 10
    Col2="Last Name" Char Width 9
    Col3="HireDate" Date Width 8
NOTE: Make sure both the Contacts.txt and Schema.ini files are stored in the same folder. For the purposes of this example, create a new folder called TestData on drive C and save both files in that folder.

Example

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

To create a table linked to a text file (Contacts.txt), follow thesesteps:
  1. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
  2. Type the following procedure:
    Function LinkSchema()   Dim db As DAO.DATABASE, tbl As DAO.TableDef   Set db = CurrentDb()   Set tbl = db.CreateTableDef("Linked Text")   tbl.Connect = "Text;DATABASE=c:\TestData;TABLE=contacts.txt"   tbl.SourceTableName = "contacts.txt"   db.TableDefs.Append tbl   db.TableDefs.RefreshEnd Function					
  3. To test this function, type the following line in the Immediate window, and then press ENTER:
    ?LinkSchema()
    In the Database window, click Tables and note that a linked table is added to the database.
REFERENCES
For more information about accessing data in a text file, click Microsoft Access Help on the Help menu, type link to fixed-width text files in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
schema ini
Properties

Article ID: 210073 - Last Review: 12/05/2015 11:19:11 - Revision: 2.0

Microsoft Access 2000 Standard Edition

  • kbnosurvey kbarchive kbhowto kbdta kb3rdparty KB210073
Feedback