Using Access Collections

The Source Code...

  ' Constants Used
  ' From DATACONS.TXT
  Const DB_BOOLEAN = 1
  Const DB_BYTE = 2
  Const DB_INTEGER = 3
  Const DB_LONG = 4
  Const DB_CURRENCY = 5
  Const DB_SINGLE = 6
  Const DB_DOUBLE = 7
  Const DB_DATE = 8
  Const DB_TEXT = 10
  Const DB_LONGBINARY = 11
  Const DB_MEMO = 12

  ' From the VB Help File
  Const DB_SYSTEMOBJECT = &H80000002
  Const DB_ATTACHEDTABLE = &H40000000
  Const DB_ATTACHEDODBC = &H20000000
  
  Sub cmdPrint_Click () 
  Dim DBF As Database 
  Dim iNoOfTables As Integer 
  Dim iPrintTable As Integer 
  Dim i As Integer 
  ReDim sPrtLine(0 To 3) As String 

  Panel3d1.Caption = "" 
  Screen.MousePointer = HOURGLASS 
  Set DBF = OpenDatabase(Text1) 
  iNoOfTables = DBF.TableDefs.Count 
  If iNoOfTables > 0 Then 
    Printer.Print 
    Printer.FontBold = True 
    Printer.Print "Definitions for Tables in " &UCase$(Text1) 
    Printer.Print "as at " & Format$(Now,"Medium Date") & 
                  " " & Format$(Now,"Medium Time") 
    Printer.FontBold = False 
    Printer.Print 
    For iPrintTable = 0 To iNoOfTables - 1 
      Panel3d1.FloodPercent = (iPrintTable+1) / iNoOfTables * 100 
      Panel3d1.Refresh 
      DoEvents 
      If (DBF.TableDefs (iPrintTable).Attributes And DB_SYSTEMOBJECT) = False 
  Then 
  ' Check if it is a System - Don't print 
    Printer.FontBold = True 
    Printer.Print DBF.TableDefs(iPrintTable).Name 
    Printer.FontBold = False 
  ' Check if it is attached or External
    If DBF.TableDefs(iPrintTable).Attributes And DB_ATTACHEDTABLE Then 
      Printer.FontBold = True 
      Printer.FontItalic = True
      Printer.Print Space(4); "ATTACHED TABLE"
      Printer.FontBold = False 
      Printer.FontItalic =  False 	
     ElseIf DBF.TableDefs (iPrintTable).Attributes And DB_ATTACHEDODBC Then 
      Printer.FontBold = True 
      Printer.FontItalic =  True 
      Printer.Print Space(4); "ATTACHED ODBC TABLE" 
      Printer.FontBold = False 
      Printer.FontItalic =  False
    End If 
    Printer.Print 
    If DBF.TableDefs(iPrintTable).Indexes.Count > 0 Then 
      Printer.FontItalic = True 
      Printer.Print "Indexes"
      Printer.FontItalic = False 
      For i = 0 To DBF.TableDefs(iPrintTable).Indexes.Count- 1 
        Printer.Print DBF.TableDefs(iPrintTable).Indexes(i).Name;Tab(20); 
        Printer.Print DBF.TableDefs(iPrintTable).Indexes(i).Fields 
      Next i
    End If 
      Printer.Print String$(40, "-") 
      Printer.FontItalic = True 
      Printer.Print "Fields"
      Printer.Print 
  Space(4);"Name";Tab(40);"Types-Access";Tab(60);"VB";Tab(80);"Size"
    	Printer.FontItalic = False 
      Printer.Print String$(90, "-") 
      For i = 0 To DBF.TableDefs(iPrintTable).Fields.Count- 1 
        sPrtLine(0) = DBF.TableDefs(iPrintTable).Fields(i).Name 
        Select Case DBF.TableDefs(iPrintTable).Fields(i).Type 
          Case DB_BOOLEAN 
          sPrtLine(1) = "Boolean" 
          sPrtLine(2) = "Integer(0 or-1)"
          ' and all the other types  
          ' in similar fashion
          Case DB_BYTE 
          Case DB_INTEGER 
          Case DB_LONG 
          Case DB_CURRENCY 
          Case DB_SINGLE 
          Case DB_DOUBLE 
          Case DB_DATE 
          Case DB_TEXT 
          Case DB_LONGBINARY 
          Case DB_MEMO 
        End Select 
        sPrtLine(3) = DBF.TableDefs(iPrintTable).Fields(i).Size 
        Printer.Print Tab(4); 
        Printer.FontBold = True 
        Printer.Print sPrtLine(0); 
        Printer.FontBold = False 
        Printer.Print Tab(40); sPrtLine(1); Tab(60); sPrtLine(2); 
                      Tab(80); Right$(Space(4) & sPrtLine(3), 4) 
      Next i                
      Printer.Print String$(90, "=") 
      Printer.Print 
      End If 
    Next iPrintTable 
    Printer.NewPage 
    Printer.EndDoc 
  End If 
  DoEvents 
  DBF.Close 
  Panel3d1.FloodPercent = 0 
  Screen.MousePointer = DEFAULT 
  End Sub 


Image of arrow to previous article

[HOME] [TABLE OF CONTENTS] [SEARCH]