文章編號: 155512 - 上次校閱: 2007年1月19日 - 版次: 3.3

ACC: 如何以程式設計方式建立 Schema.ini 檔案

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
中級使用者: 需要基本巨集]、 [程式碼撰寫,] 以及 [交互操作性技巧。
全部展開 | 全部摺疊

結論

本文將告訴您如何撰寫會建立 Schema.ini 檔案,根據您的資料庫中的現有資料表的程序。

本文假設您已熟悉使用 Visual Basic 應用程式以及建立 Microsoft Access 應用程式使用程式設計與 Microsoft Access 所提供的工具。如需有關 Visual Basic 應用程式,請參閱您的建置應用程式與 Microsoft 存取] 手冊版本。

其他相關資訊

在 Microsoft Access 7.0 與 Microsoft Access 97 中,您可以連結,或開啟分隔和固定長度的文字檔案。Microsoft Access 可以直接,讀取文字檔案,或者它可以使用稱為 Schema.ini 的資訊檔來決定文字檔例如資料行名稱、 欄位長度和資料類型的特性。Schema.ini 檔案時,需要您要連結或開啟固定長度的文字檔案,它是選擇性的分隔的文字檔案。Schema.ini 檔案必須位於相同它說明了文字檔案的資料夾。

在下列範例程序接受四個參數:
     Parameter        Value
   ------------------------------------------------------------------------
   bIncFldNames     True/False, stating if the first row of the text file
                    has column names
   sPath            Full path to the folder where Schema.ini will reside
   sSectionName     Schema.ini section name; must be the same as the name
                    of the text file it describes
   sTblQryName      Name of the table or query for which you want to
                    create a Schema.ini file
				
警告: 在此範例中的程序將會覆寫現有的 Schema.ini 檔案在相同的目的地資料夾不會發出警告。
  1. 開啟範例資料庫 Northwind.mdb。
  2. 建立模組,如果它已經不存在,請宣告區段中輸入下面這一行: 選項明確
  3. 鍵入下列程序:
          Public Function CreateSchemaFile(bIncFldNames As Boolean, _
                                           sPath As String, _
                                           sSectionName As String, _
                                           sTblQryName As String) As Boolean
             Dim Msg As String ' For error handling.
             On Local Error GoTo CreateSchemaFile_Err
             Dim ws As Workspace, db As DATABASE
             Dim tblDef As TableDef, fldDef As Field
             Dim i As Integer, Handle As Integer
             Dim fldName As String, fldDataInfo As String
             ' -----------------------------------------------
             ' Set DAO objects.
             ' -----------------------------------------------
             Set db = CurrentDB()
             ' -----------------------------------------------
             ' Open schema file for append.
             ' -----------------------------------------------
             Handle = FreeFile
             Open sPath & "schema.ini" For Output Access Write As #Handle
             ' -----------------------------------------------
             ' Write schema header.
             ' -----------------------------------------------
             Print #Handle, "[" & sSectionName & "]"
             Print #Handle, "ColNameHeader = " & _
                             IIf(bIncFldNames, "True", "False")
             Print #Handle, "CharacterSet = ANSI"
             Print #Handle, "Format = TabDelimited"
             ' -----------------------------------------------
             ' Get data concerning schema file.
             ' -----------------------------------------------
             Set tblDef = db.TableDefs(sTblQryName)
             With tblDef
                For i = 0 To .Fields.Count - 1
                   Set fldDef = .Fields(i)
                   With fldDef
                      fldName = .Name
                      Select Case .Type
                         Case dbBoolean
                            fldDataInfo = "Bit"
                         Case dbByte
                            fldDataInfo = "Byte"
                         Case dbInteger
                            fldDataInfo = "Short"
                         Case dbLong
                            fldDataInfo = "Integer"
                         Case dbCurrency
                            fldDataInfo = "Currency"
                         Case dbSingle
                            fldDataInfo = "Single"
                         Case dbDouble
                            fldDataInfo = "Double"
                         Case dbDate
                            fldDataInfo = "Date"
                         Case dbText
                            fldDataInfo = "Char Width " & Format$(.Size)
                         Case dbLongBinary
                            fldDataInfo = "OLE"
                         Case dbMemo
                            fldDataInfo = "LongChar"
                         Case dbGUID
                            fldDataInfo = "Char Width 16"
                      End Select
                      Print #Handle, "Col" & Format$(i + 1) _
                                      & "=" & fldName & Space$(1) _
                                      & fldDataInfo
                   End With
                Next i
             End With
             MsgBox sPath & "SCHEMA.INI has been created."
             CreateSchemaFile = True
          CreateSchemaFile_End:
             Close Handle
             Exit Function
          CreateSchemaFile_Err:
             Msg = "Error #: " & Format$(Err.Number) & vbCrLf
             Msg = Msg & Err.Description
             MsgBox Msg
             Resume CreateSchemaFile_End
          End Function
    						
  4. 測試這個函式、 偵錯] 視窗中輸入下列命令,然後按下 ENTER:
    ?? CreateSchemaFile(True,"c:\MSOffice\Access\","EMP.TXT","Employees")
  5. 開啟您使用像 「 記事本 」 或 Wordpad 的文字編輯器建立的 Schema.ini 檔案。請注意該檔案包含下列資訊:
    [EMP.TXT]
    ColNameHeader = True
    CharacterSet = ANSI
    格式 = TabDelimited
    欄 1 = 員工編號的整數
    Col2 = [姓氏] char 寬度 20
    Col3 = 名字 char 寬度為 10
    Col4 = 標題 char 寬度 30
    Col5 = TitleOfCourtesy char 寬度 25
    Col6 = 生日日期
    Col7 = 雇用日期的日期
    Col8 = 位址 char 寬度 60
    Col9 = 城市 char 寬度 15
    Col10 = 地區 char 寬度 15
    Col11 = [郵遞區號] char 寬度為 10
    Col12 = 國家 (地區) char 寬度 15
    Col13 = 住家電話 char 寬度 24
    Col14 = 副檔名 char 寬度 4
    Col15 = 相片 OLE
    Col16 = 備忘稿 LongChar
    Col17 = 上司整數

?考

它包含的資訊和關於 Schema.ini 檔案的詳細資訊,搜尋 初始化驅動程式,然後再 初始化文字資料來源驅動程式 使用 Microsoft Access 97 說明索引。

如需 Schema.ini 檔案和到 Microsoft Access,然後在 Microsoft Jet 資料庫引擎及其關聯性的詳細資訊,請參閱 < Microsoft Jet 資料庫引擎程式設計人員指南,"頁 306 312。

這篇文章中的資訊適用於:
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
關鍵字:?
kbmt kbhowto kbprogramming KB155512 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:155512? (http://support.microsoft.com/kb/155512/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。
Retired KB Article依現狀不再更新的知識庫內容免責聲明
本文旨在說明 Microsoft 不再提供支援的產品。因此,本文係依「現狀」提供,不會再更新。