/ Published in: Visual Basic
Expand |
Embed | Plain Text
Sub t() CreateSchemaFile True, "C:\temp\", "EMP.TXT", "tblTest6" End Sub 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 DAO.Database Dim tblDef As DAO.TableDef, fldDef As DAO.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, fldName & "," & 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
You need to login to post a comment.
