home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / execut1r / frmdbv~1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-30  |  31.3 KB  |  867 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  4. Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
  5. Begin VB.Form frmDBViewer 
  6.    Caption         =   "Database Viewer"
  7.    ClientHeight    =   7395
  8.    ClientLeft      =   2040
  9.    ClientTop       =   900
  10.    ClientWidth     =   7155
  11.    ClipControls    =   0   'False
  12.    ControlBox      =   0   'False
  13.    Icon            =   "frmDBViewer.frx":0000
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   7395
  18.    ScaleWidth      =   7155
  19.    Begin VB.PictureBox Picture1 
  20.       Height          =   7440
  21.       Left            =   -45
  22.       ScaleHeight     =   7380
  23.       ScaleWidth      =   8415
  24.       TabIndex        =   0
  25.       Top             =   -45
  26.       Width           =   8475
  27.       Begin MSDBGrid.DBGrid DBGrid1 
  28.          Bindings        =   "frmDBViewer.frx":0442
  29.          Height          =   3030
  30.          Left            =   90
  31.          OleObjectBlob   =   "frmDBViewer.frx":0459
  32.          TabIndex        =   12
  33.          Top             =   4230
  34.          Width           =   7035
  35.       End
  36.       Begin ComctlLib.TabStrip TabStrip1 
  37.          Height          =   330
  38.          Left            =   4725
  39.          TabIndex        =   14
  40.          Top             =   315
  41.          Width           =   1755
  42.          _ExtentX        =   3096
  43.          _ExtentY        =   582
  44.          Style           =   1
  45.          TabFixedWidth   =   1764
  46.          _Version        =   327682
  47.          BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7} 
  48.             NumTabs         =   2
  49.             BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  50.                Caption         =   "Access"
  51.                Object.Tag             =   ""
  52.                ImageVarType    =   2
  53.             EndProperty
  54.             BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  55.                Caption         =   "FoxPro 2.6"
  56.                Object.Tag             =   ""
  57.                ImageVarType    =   2
  58.             EndProperty
  59.          EndProperty
  60.       End
  61.       Begin VB.CommandButton cmdPrintGrid 
  62.          Caption         =   "Print"
  63.          Height          =   285
  64.          Left            =   6210
  65.          TabIndex        =   13
  66.          ToolTipText     =   "Click here to 'Print' the data."
  67.          Top             =   5490
  68.          Visible         =   0   'False
  69.          Width           =   690
  70.       End
  71.       Begin VB.TextBox txt 
  72.          BackColor       =   &H00FFFF00&
  73.          BeginProperty Font 
  74.             Name            =   "Times New Roman"
  75.             Size            =   8.25
  76.             Charset         =   0
  77.             Weight          =   400
  78.             Underline       =   0   'False
  79.             Italic          =   0   'False
  80.             Strikethrough   =   0   'False
  81.          EndProperty
  82.          Height          =   315
  83.          Left            =   90
  84.          TabIndex        =   11
  85.          ToolTipText     =   "Search on the first field of the grid below."
  86.          Top             =   3825
  87.          Width           =   1680
  88.       End
  89.       Begin VB.Timer Timer1 
  90.          Interval        =   1500
  91.          Left            =   630
  92.          Top             =   5805
  93.       End
  94.       Begin VB.Data dbGridSource 
  95.          Caption         =   "dbGridSource"
  96.          Connect         =   "Access"
  97.          DatabaseName    =   ""
  98.          DefaultCursorType=   0  'DefaultCursor
  99.          DefaultType     =   2  'UseODBC
  100.          Exclusive       =   0   'False
  101.          Height          =   345
  102.          Left            =   1350
  103.          Options         =   0
  104.          ReadOnly        =   0   'False
  105.          RecordsetType   =   1  'Dynaset
  106.          RecordSource    =   ""
  107.          Top             =   5715
  108.          Visible         =   0   'False
  109.          Width           =   1140
  110.       End
  111.       Begin VB.CommandButton cmdRefresh 
  112.          Caption         =   "&Refresh"
  113.          Height          =   285
  114.          Left            =   4905
  115.          TabIndex        =   9
  116.          ToolTipText     =   "Refresh the Tree View."
  117.          Top             =   3600
  118.          Width           =   690
  119.       End
  120.       Begin VB.CommandButton cmdPrint 
  121.          Caption         =   "&Print"
  122.          Enabled         =   0   'False
  123.          Height          =   285
  124.          Left            =   5625
  125.          TabIndex        =   8
  126.          ToolTipText     =   "Click here to print Table Structure."
  127.          Top             =   3600
  128.          Width           =   690
  129.       End
  130.       Begin VB.CommandButton cmdClose 
  131.          Caption         =   "&Close"
  132.          Height          =   285
  133.          Left            =   6345
  134.          TabIndex        =   7
  135.          ToolTipText     =   "Click here to 'Close' the program."
  136.          Top             =   3600
  137.          Width           =   690
  138.       End
  139.       Begin ComctlLib.ProgressBar PBar 
  140.          Height          =   195
  141.          Index           =   0
  142.          Left            =   90
  143.          TabIndex        =   6
  144.          Top             =   3240
  145.          Visible         =   0   'False
  146.          Width           =   6945
  147.          _ExtentX        =   12250
  148.          _ExtentY        =   344
  149.          _Version        =   327682
  150.          Appearance      =   1
  151.       End
  152.       Begin VB.CommandButton cmd 
  153.          Caption         =   "..."
  154.          BeginProperty Font 
  155.             Name            =   "Times New Roman"
  156.             Size            =   12
  157.             Charset         =   0
  158.             Weight          =   700
  159.             Underline       =   0   'False
  160.             Italic          =   -1  'True
  161.             Strikethrough   =   0   'False
  162.          EndProperty
  163.          Height          =   285
  164.          Left            =   3960
  165.          TabIndex        =   3
  166.          ToolTipText     =   "Click here to select a database."
  167.          Top             =   360
  168.          Width           =   330
  169.       End
  170.       Begin VB.TextBox txtPath 
  171.          BackColor       =   &H00FFFF00&
  172.          BeginProperty Font 
  173.             Name            =   "Times New Roman"
  174.             Size            =   8.25
  175.             Charset         =   0
  176.             Weight          =   400
  177.             Underline       =   0   'False
  178.             Italic          =   0   'False
  179.             Strikethrough   =   0   'False
  180.          EndProperty
  181.          Height          =   285
  182.          Left            =   135
  183.          TabIndex        =   2
  184.          ToolTipText     =   "Type in a database name with full path. Then click the 'Refresh' button."
  185.          Top             =   360
  186.          Width           =   3840
  187.       End
  188.       Begin ComctlLib.StatusBar StatusBar1 
  189.          Height          =   285
  190.          Left            =   90
  191.          TabIndex        =   4
  192.          Top             =   765
  193.          Width           =   6915
  194.          _ExtentX        =   12197
  195.          _ExtentY        =   503
  196.          SimpleText      =   ""
  197.          _Version        =   327682
  198.          BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  199.             NumPanels       =   3
  200.             BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  201.                Object.Width           =   7056
  202.                MinWidth        =   7056
  203.                Text            =   "                      Tables / Fields"
  204.                TextSave        =   "                      Tables / Fields"
  205.                Object.Tag             =   ""
  206.             EndProperty
  207.             BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  208.                Alignment       =   1
  209.                Text            =   "Field Type"
  210.                TextSave        =   "Field Type"
  211.                Object.Tag             =   ""
  212.             EndProperty
  213.             BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  214.                Alignment       =   1
  215.                Text            =   "Field Size"
  216.                TextSave        =   "Field Size"
  217.                Object.Tag             =   ""
  218.             EndProperty
  219.          EndProperty
  220.       End
  221.       Begin ComctlLib.TreeView tvStructure 
  222.          Height          =   2355
  223.          Left            =   90
  224.          TabIndex        =   5
  225.          Top             =   1080
  226.          Width           =   6945
  227.          _ExtentX        =   12250
  228.          _ExtentY        =   4154
  229.          _Version        =   327682
  230.          Indentation     =   706
  231.          Style           =   7
  232.          ImageList       =   "ImageList1"
  233.          BorderStyle     =   1
  234.          Appearance      =   1
  235.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  236.             Name            =   "Courier"
  237.             Size            =   9.75
  238.             Charset         =   0
  239.             Weight          =   400
  240.             Underline       =   0   'False
  241.             Italic          =   0   'False
  242.             Strikethrough   =   0   'False
  243.          EndProperty
  244.       End
  245.       Begin MSComDlg.CommonDialog cdlgPath 
  246.          Left            =   2745
  247.          Top             =   5805
  248.          _ExtentX        =   847
  249.          _ExtentY        =   847
  250.          _Version        =   327681
  251.          DialogTitle     =   "Database Search"
  252.          FileName        =   "*.MDB"
  253.          Filter          =   "*.MDB"
  254.          InitDir         =   "C:\CMISHOP"
  255.       End
  256.       Begin VB.Label lblError 
  257.          AutoSize        =   -1  'True
  258.          BorderStyle     =   1  'Fixed Single
  259.          Height          =   255
  260.          Left            =   1845
  261.          TabIndex        =   10
  262.          Top             =   3870
  263.          Visible         =   0   'False
  264.          Width           =   105
  265.       End
  266.       Begin ComctlLib.ImageList ImageList1 
  267.          Left            =   3600
  268.          Top             =   5760
  269.          _ExtentX        =   1005
  270.          _ExtentY        =   1005
  271.          BackColor       =   -2147483643
  272.          ImageWidth      =   13
  273.          ImageHeight     =   13
  274.          MaskColor       =   12632256
  275.          _Version        =   327682
  276.          BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  277.             NumListImages   =   2
  278.             BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  279.                Picture         =   "frmDBViewer.frx":0E2C
  280.                Key             =   "Folder"
  281.             EndProperty
  282.             BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  283.                Picture         =   "frmDBViewer.frx":0F26
  284.                Key             =   "Table"
  285.             EndProperty
  286.          EndProperty
  287.       End
  288.       Begin VB.Label lbl 
  289.          Caption         =   "Database Path:"
  290.          BeginProperty Font 
  291.             Name            =   "Small Fonts"
  292.             Size            =   6.75
  293.             Charset         =   0
  294.             Weight          =   400
  295.             Underline       =   0   'False
  296.             Italic          =   0   'False
  297.             Strikethrough   =   0   'False
  298.          EndProperty
  299.          Height          =   195
  300.          Index           =   0
  301.          Left            =   180
  302.          TabIndex        =   1
  303.          Top             =   135
  304.          Width           =   1140
  305.       End
  306.    End
  307.    Begin VB.Menu mnuOptions 
  308.       Caption         =   "Options"
  309.       Visible         =   0   'False
  310.       Begin VB.Menu mnuRefreshTree 
  311.          Caption         =   "Refresh Tree"
  312.       End
  313.       Begin VB.Menu mnuPrintStructure 
  314.          Caption         =   "Print Structure"
  315.          Enabled         =   0   'False
  316.       End
  317.       Begin VB.Menu mnublank1 
  318.          Caption         =   "-"
  319.       End
  320.       Begin VB.Menu mnuChangeColor 
  321.          Caption         =   "Change Colors"
  322.       End
  323.       Begin VB.Menu mnublank2 
  324.          Caption         =   "-"
  325.       End
  326.       Begin VB.Menu mnuClose 
  327.          Caption         =   "Close"
  328.       End
  329.    End
  330. Attribute VB_Name = "frmDBViewer"
  331. Attribute VB_GlobalNameSpace = False
  332. Attribute VB_Creatable = False
  333. Attribute VB_PredeclaredId = True
  334. Attribute VB_Exposed = False
  335. '**********************************************************************************
  336. ' DBViewer Part 2 - Database Viewer
  337. ' Released into the public domain by Orval Stewart of Uptown Electronics
  338. ' 11-29-1998  Developed by Orval Stewart  - orval@texhoma.net - uptown@texhoma.net
  339. ' Purpose:
  340. ' I was asked to develope a program to convert data from one type of database to
  341. ' another. That put me in need of a program that would show not only the data within
  342. ' a wide range of databases but also to view its structure. This is the first of that
  343. ' series of programs developed for that end. The only database types I needed at this
  344. ' time was FoxPro 2.6 and Access. This program has been written in a form to allow the
  345. ' programmer to easily adapt it to the other databases accessable by ISAM.
  346. ' Lessons to be learned:
  347. ' (1)   Manipulation of data objects.
  348. '       (A) Retrieving structure information through Table Definitions.
  349. '       (B) Getting Field Count, Name, Type, and Size.
  350. '       (C) Using the same code to manipulate many types of databases.
  351. ' (2)   Usage of the TreeView object.
  352. '       (A) Displaying the Table name, Field name, Fields type, and Field Size.
  353. '       [See the cmdRefresh_Click code.]
  354. ' (3)   Usage of the DBGrid control.
  355. '       (A) Assigning different types of databases to the grid control.
  356. '       (B) Aligning the grid to a text box control for search purposes.
  357. ' (4)   How to simulate the IE4 address bar search functions.
  358. '       [Neat process here. If you start typing in the text box above the grid it
  359. '       will try to anticipate what you are looking for by immediatly searching the
  360. '       current database for a similar match to what you are typing. If it finds a
  361. '       similar match then it adds the rest of the information to what you are typing
  362. '       and then highlights everything to the right of the cursor. It also aligns the
  363. '       grid to the proper record. If it does not find a proper match then a small
  364. '       error box appears for a preset period of time and then removes the last
  365. '       character you typed in to cause the error.]
  366. ' (5)   Usage of the Common Dialog.
  367. '       [Straight forward process here. You tell the common dialog what you want to
  368. '       display, such as a Dir/Files listing. Boom it does it.]
  369. ' (6)   Usage of the TabStrip button style.
  370. '       (A) Setting the property page to button style.
  371. '       (B) Processing the button clicks.
  372. ' (7)   Usage of a progress bar.
  373. ' (8)   Usage of a status bar.
  374. '***********************************************************************************
  375. 'Force Variable Declaration
  376. Option Explicit
  377. 'TreeView Node variable
  378. Dim mNode As Node
  379. 'DAO variables use while loading the TreeView with structure data
  380. Dim Db As Database
  381. Dim Rs As Recordset
  382. 'Loop Counters for loading the TreeView with structure data
  383. Dim A As Integer
  384. Dim B As Integer
  385. Dim C As Integer
  386. Dim I As Integer
  387. 'String variable to hold the SQL
  388. Dim Criteria As String
  389. 'String variable to hold the Field Type information
  390. Dim FieldType As String
  391. 'String variable to hold the Table Name information
  392. Dim TableName As String
  393. Private Sub cmd_Click()
  394. txt = ""
  395. txt.Enabled = False
  396. 'Setup the Common Dialog to show us Files
  397. cdlgPath.DialogTitle = "Locate Database"
  398. cdlgPath.CancelError = True
  399. cdlgPath.Flags = cdlOFNLongNames + cdlOFNNoChangeDir + cdlOFNExplorer
  400. On Error GoTo ErrorHandler
  401. Select Case TabStrip1.SelectedItem
  402.   Case "Access"
  403.     'Setup the Common Dialog to show us Access Database Files
  404.     cdlgPath.filename = "*.MDB"
  405.     'The InitDir text may be changed to reflect your database location
  406.     'cdlgPath.InitDir = "C:\CMISHOP"
  407.     cdlgPath.ShowOpen
  408.     DoEvents
  409.     txtPath = cdlgPath.filename
  410.   Case "FoxPro 2.6"
  411.     'Setup the Common Dialog to show us Fox Pro Files
  412.     cdlgPath.filename = "*.DBF"
  413.     'The InitDir text may be changed to reflect your database location
  414.     'cdlgPath.InitDir = "D:\AMP\SIS1"
  415.     cdlgPath.ShowOpen
  416.     DoEvents
  417.     'The following code is required because of the unusual nature of a FoxPro database file.
  418.     'Microsoft's DAO see's each DBF file as a table. So after selecting any DBF file in the
  419.     'Common Dialog then you need to parse out the file name and just use the remaining
  420.     'path. This also means that all the DBF files in the path you selected will be loaded.
  421.     'This can some times take a while to read into the TreeView.
  422.     Dim InPosition As Integer
  423.     InPosition = InStr(cdlgPath.filename, cdlgPath.FileTitle)
  424.     txtPath = Mid(cdlgPath.filename, 1, InPosition - 2)
  425. End Select
  426. 'Have the system click the 'Refresh' button on the form.
  427. 'This will fill the TreeView with the database you have just selected.
  428. cmdRefresh_Click
  429. Exit Sub
  430. ErrorHandler:
  431.   Exit Sub
  432. End Sub
  433. Private Sub cmd_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  434. 'If Right mouse button the show menu.
  435. If Button = 2 Then
  436.   PopupMenu mnuOptions
  437. End If
  438. End Sub
  439. Private Sub cmdClose_Click()
  440. 'Quit
  441. Unload Me
  442. End Sub
  443. Private Sub cmdClose_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  444. 'If Right mouse button the show menu.
  445. If Button = 2 Then
  446.   PopupMenu mnuOptions
  447. End If
  448. End Sub
  449. Private Sub cmdPrint_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  450. 'If Right mouse button the show menu.
  451. If Button = 2 Then
  452.   PopupMenu mnuOptions
  453. End If
  454. End Sub
  455. Private Sub cmdPrint_Click()
  456. On Error GoTo FixError
  457. 'Setup and display the Print Dialog box
  458. cdlgPath.DialogTitle = "Database Print"
  459. cdlgPath.CancelError = True
  460. cdlgPath.Flags = cdlOFNLongNames + cdlOFNNoChangeDir + cdlOFNExplorer
  461. cdlgPath.ShowPrinter
  462. GoSub PrintIt
  463. Exit Sub
  464. PrintIt:
  465.   DoEvents
  466.   Screen.MousePointer = 13
  467.   Set Rs = Db.OpenRecordset(TableName)
  468.   Printer.Font = "Courier New"
  469.   Printer.Orientation = vbPRORPortrait
  470.   Printer.FontSize = 12
  471.   Printer.FontBold = True
  472.   Printer.Print
  473.   Printer.Print "Database Name: " & txtPath
  474.   Printer.Print "Table Name: " & TableName
  475.   Printer.Print
  476.   Printer.Font.Underline = True
  477.   Printer.Print "Field name                    Type         Size"
  478.   Printer.Font.Underline = False
  479.   Printer.FontBold = False
  480.   Printer.Print
  481.   For B = 0 To Rs.Fields.Count - 1
  482.     If Rs.Fields(B).Name <> "ID" Then
  483.       GoSub FixType
  484.       If Rs.Fields(B).Type = 7 Then
  485.         Printer.Print Rs.Fields(B).Name & Space(25 - Len(Rs.Fields(B).Name) + 5) & FieldType
  486.       Else
  487.         Printer.Print Rs.Fields(B).Name & Space(25 - Len(Rs.Fields(B).Name) + 5) & FieldType & Space(8 - Len(FieldType) + 5) & Rs.Fields(B).Size
  488.       End If
  489.     End If
  490.   Next B
  491.   Printer.EndDoc
  492.   Screen.MousePointer = 0
  493.   Return
  494. FixType:
  495. Screen.MousePointer = 0
  496. Select Case Rs.Fields(B).Type
  497.   Case dbBoolean
  498.     FieldType = "Boolean"
  499.   Case dbByte
  500.     FieldType = "Byte"
  501.   Case dbInteger
  502.     FieldType = "Integer"
  503.   Case dbLong
  504.     FieldType = "Long"
  505.   Case dbCurrency
  506.     FieldType = "Currency"
  507.   Case dbSingle
  508.     FieldType = "Single"
  509.   Case dbDouble
  510.     FieldType = "Double"
  511.   Case dbDate
  512.     FieldType = "Date"
  513.   Case dbText
  514.     FieldType = "Text"
  515.   Case dbLongBinary
  516.     FieldType = "LongBinary"
  517.   Case dbMemo
  518.     FieldType = "Memo"
  519.   Case dbGUID
  520.     FieldType = "GUID"
  521. End Select
  522. Return
  523. FixError:
  524. Resume GetOut
  525. GetOut:
  526. End Sub
  527. Private Sub cmdRefresh_Click()
  528. 'Make sure there is a database to process
  529. If Trim(txtPath) = "" Then
  530.   MsgBox "No database selected to process.", vbCritical + vbOKOnly, "Warning"
  531.   txtPath.SetFocus
  532.   Exit Sub
  533. End If
  534. 'Incremental Index variables
  535. Dim TableIndex As Integer
  536. Dim FieldsIndex As Integer
  537. txt = ""
  538. txt.Enabled = False
  539. Screen.MousePointer = 13
  540. On Error GoTo FixError
  541. 'Determine the type of database we are dealing with.
  542. Select Case TabStrip1.SelectedItem
  543.   Case "Access"
  544.     Set Db = OpenDatabase(txtPath, , True, "Access")
  545.   Case "FoxPro 2.6"
  546.     Set Db = OpenDatabase(txtPath, False, False, "FoxPro 2.6;")
  547. End Select
  548. On Error GoTo 0
  549. ' Expand top node. (This means display all the tables but not the fields)
  550. If tvStructure.Nodes.Count > 0 Then
  551.   tvStructure.Nodes(1).Expanded = False
  552. End If
  553. 'Clean up the TreeView in case it has information in it now.
  554. tvStructure.Nodes.Clear
  555. ' Configure TreeView
  556. tvStructure.Sorted = True
  557. Set mNode = tvStructure.Nodes.Add()
  558. mNode.Text = "Tables"
  559. mNode.Tag = Db.Name
  560. mNode.Image = "Folder"
  561. tvStructure.LabelEdit = tvwManual
  562. 'Setup and Display the Progress bar
  563. PBar(0).Visible = True
  564. PBar(0).Max = Db.TableDefs.Count - 1
  565. 'Main loop to fill the TreeView with data
  566. For A = 0 To Db.TableDefs.Count - 1   'Db.TableDefs.Count contains the total number of tables.
  567.   PBar(0).Value = A
  568.   If Left(Db.TableDefs(A).Name, 4) <> "MSys" Then   'Weed out the Microsoft System tables.
  569.     'Setup the Table Node
  570.     Set mNode = tvStructure.Nodes.Add(1, tvwChild, , Db.TableDefs(A).Name, "Table")
  571.     mNode.Tag = "Tables" ' Identifies the table.
  572.     TableIndex = mNode.Index
  573.     'Open a Recordset from the above TableDefs
  574.     Set Rs = Db.OpenRecordset(Db.TableDefs(A).Name)
  575.     For B = 0 To Rs.Fields.Count - 1    'Rs.Fields.Count contains the total number of fields.
  576.       If Rs.Fields(B).Name <> "ID" Then
  577.         'Setup the Field Node
  578.         Set mNode = tvStructure.Nodes.Add(TableIndex, tvwChild)
  579.         'Jump out of the loop to determine the Field Type
  580.         GoSub FixType
  581.         If Rs.Fields(B).Type = dbBoolean Or Rs.Fields(B).Type = dbMemo Then
  582.           'Has no Field Size
  583.           mNode.Text = Rs.Fields(B).Name & Space(25 - Len(Rs.Fields(B).Name) + 5) & FieldType
  584.         Else
  585.           'Has a Field Size so Display it.
  586.           mNode.Text = Rs.Fields(B).Name & Space(25 - Len(Rs.Fields(B).Name) + 5) & FieldType & Space(8 - Len(FieldType) + 5) & Rs.Fields(B).Size
  587.         End If
  588.         mNode.Tag = "Fields"
  589.         FieldsIndex = mNode.Index
  590.       End If
  591.     Next B  'Loop Fields
  592.   End If
  593. Next A  'Loop Tables
  594. DoEvents
  595. 'Turn off the Progress Bar
  596. PBar(0).Visible = False
  597. ' Sort the OperationTime nodes.
  598. For I = 1 To tvStructure.Nodes.Count - 1
  599.   tvStructure.Nodes(I).Sorted = True
  600. Next I
  601. Screen.MousePointer = 0
  602. ' Expand top node.
  603. tvStructure.Nodes(1).Expanded = True
  604. tvStructure.SetFocus
  605. SendKeys "{HOME}", True
  606. Exit Sub
  607. FixType:
  608. 'Determine the Field Type through the 'Select Case' method
  609. 'The Rs.Fields(B).Type only contains a number and you must determine the text name to display
  610. 'so the viewer can tell what the TreeView is displaying.
  611. 'Microsoft has given us a few constants so we can make the determination.
  612. Select Case Rs.Fields(B).Type
  613.   Case dbBoolean
  614.     FieldType = "Boolean"
  615.   Case dbByte
  616.     FieldType = "Byte"
  617.   Case dbInteger
  618.     FieldType = "Integer"
  619.   Case dbLong
  620.     FieldType = "Long"
  621.   Case dbCurrency
  622.     FieldType = "Currency"
  623.   Case dbSingle
  624.     FieldType = "Single"
  625.   Case dbDouble
  626.     FieldType = "Double"
  627.   Case dbDate
  628.     FieldType = "Date"
  629.   Case dbText
  630.     FieldType = "Text"
  631.   Case dbLongBinary
  632.     FieldType = "LongBinary"
  633.   Case dbMemo
  634.     FieldType = "Memo"
  635.   Case dbGUID
  636.     FieldType = "GUID"
  637. End Select
  638. 'Go back to the loop
  639. Return
  640. FixError:
  641. Screen.MousePointer = 0
  642. 'Display the problem and the quit the sub-program
  643. MsgBox Error$
  644. Resume GetOut
  645. GetOut:
  646. End Sub
  647. Private Sub DBGrid1_Click()
  648. txt = ""
  649. End Sub
  650. Private Sub DBGrid1_GotFocus()
  651. txt = ""
  652. End Sub
  653. Private Sub DBGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  654. 'If Right mouse button the show menu.
  655. If Button = 2 Then
  656.   PopupMenu mnuOptions
  657. End If
  658. End Sub
  659. Private Sub Form_Activate()
  660. 'Have the system click the 'Refresh' button as soon as the Form_Load
  661. 'Sub has completed. This allows the default database to be read into the
  662. 'TreeView.
  663. If Trim(txtPath) <> "" Then
  664.   cmdRefresh_Click
  665. End If
  666. End Sub
  667. Private Sub Form_Load()
  668. '*************************************
  669. ' If you want to add initializations for other types of databases supported by Microsoft.
  670. ' Then type in the DBEngine.IniPath for this other type or types. You must also add an object(s)
  671. ' on frmDBViewer to let the system know you want to use these other types.
  672. ' I used FoxPro 2.6 as a sample below because I had some FoxPro 2.6 databases on my system.
  673. ' If you add a GetSettings statement to the code below, be sure to add its complement to the
  674. ' Form_Unload sub so it will be saved to the registry.
  675. '*************************************
  676. 'Get the default settings from the Registry.
  677. 'Assuming you want to change the defaults. Add a valid entry in the default
  678. 'section of the GetSettings function. {The last entry}
  679. DBEngine.IniPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.5\ISAM Formats\FoxPro 2.6"
  680. 'Center the form
  681. Me.Top = (Screen.Height - Height) \ 2
  682. Me.Left = (Screen.Width - Width) \ 2
  683. 'txtPath = "C:\CMISHOP\JC\OPTIME.MDB"
  684. End Sub
  685. Private Sub lbl_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  686. 'If Right mouse button the show menu.
  687. If Button = 2 Then
  688.   PopupMenu mnuOptions
  689. End If
  690. End Sub
  691. Private Sub lblError_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  692. 'If Right mouse button the show menu.
  693. If Button = 2 Then
  694.   PopupMenu mnuOptions
  695. End If
  696. End Sub
  697. Private Sub mnuClose_Click()
  698.   Unload Me
  699. End Sub
  700. Private Sub mnuPrintStructure_Click()
  701.   cmdPrint_Click
  702. End Sub
  703. Private Sub mnuRefreshTree_Click()
  704.   cmdRefresh_Click
  705. End Sub
  706. Private Sub PBar_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  707. 'If Right mouse button the show menu.
  708. If Button = 2 Then
  709.   PopupMenu mnuOptions
  710. End If
  711. End Sub
  712. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  713. 'If Right mouse button the show menu.
  714. If Button = 2 Then
  715.   PopupMenu mnuOptions
  716. End If
  717. End Sub
  718. Private Sub StatusBar1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  719. 'If Right mouse button the show menu.
  720. If Button = 2 Then
  721.   PopupMenu mnuOptions
  722. End If
  723. End Sub
  724. Private Sub TabStrip1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  725. 'If Right mouse button the show menu.
  726. If Button = 2 Then
  727.   PopupMenu mnuOptions
  728.   Exit Sub
  729. End If
  730. txt = ""
  731. txt.Enabled = False
  732. 'Clean up the TreeView in case it has information in it now.
  733. tvStructure.Nodes.Clear
  734. Select Case TabStrip1.SelectedItem
  735.   Case "Access"
  736.     'txtPath = "C:\CMISHOP\JC\OPTIME.MDB"
  737.   Case "FoxPro 2.6"
  738.     'txtPath = "D:\AMP\SIS1"
  739. End Select
  740. 'Set the focus back to txtPath object
  741. txtPath.SetFocus
  742. End Sub
  743. Private Sub Timer1_Timer()
  744. 'Disable the Timer
  745. Timer1.Enabled = False
  746. 'Hide the Error display
  747. lblError.Visible = False
  748. lblError.Caption = ""
  749. End Sub
  750. Private Sub tvStructure_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  751. 'If Right mouse button the show menu.
  752. If Button = 2 Then
  753.   PopupMenu mnuOptions
  754. End If
  755. End Sub
  756. Private Sub tvStructure_NodeClick(ByVal Node As ComctlLib.Node)
  757. 'This is where we determine what the Grid is going to display.
  758. 'If the user clicks on a Table then the Grid will display its data.
  759. Screen.MousePointer = 13
  760. Set mNode = Node
  761. If Node.Tag = "Tables" Then
  762.   cmdPrint.Enabled = True
  763.   mnuPrintStructure.Enabled = True
  764.   TableName = Node.Text
  765.   Select Case TabStrip1.SelectedItem
  766.     Case "Access"
  767.       dbGridSource.Connect = "Access"
  768.       dbGridSource.DatabaseName = txtPath
  769.       dbGridSource.RecordSource = TableName
  770.       dbGridSource.Refresh
  771.       'Determine if the Table Name contains any spaces if so add the required brackets.
  772.       If InStr(TableName, " ") Then
  773.         dbGridSource.RecordSource = "SELECT * FROM [" & TableName & "] ORDER BY " & dbGridSource.Recordset.Fields(0).Name
  774.       Else
  775.         dbGridSource.RecordSource = "SELECT * FROM " & TableName & " ORDER BY " & dbGridSource.Recordset.Fields(0).Name
  776.       End If
  777.       dbGridSource.Refresh
  778.       DBGrid1.ReBind
  779.       DBGrid1.Caption = "Sort Order by '" & dbGridSource.Recordset.Fields(0).Name & "'"
  780.     Case "FoxPro 2.6"
  781.       dbGridSource.Connect = "FoxPro 2.6"
  782.       dbGridSource.DatabaseName = txtPath
  783.       dbGridSource.RecordSource = TableName
  784.       dbGridSource.Refresh
  785.       dbGridSource.RecordSource = "SELECT * FROM " & TableName & " ORDER BY " & dbGridSource.Recordset.Fields(0).Name
  786.       dbGridSource.Refresh
  787.       DBGrid1.ReBind
  788.       DBGrid1.Caption = "Sort Order by '" & dbGridSource.Recordset.Fields(0).Name & "'"
  789.     End Select
  790.   cmdPrint.Enabled = False
  791.   mnuPrintStructure.Enabled = False
  792. End If
  793. txt = ""
  794. txt.Enabled = True
  795. Screen.MousePointer = 0
  796. End Sub
  797. Private Sub txt_KeyDown(KeyCode As Integer, Shift As Integer)
  798. 'This code handles the Search Text box above the Grid. It works similar to the IE4 address
  799. 'text in that it antisipates the users input by searching the database for similar information.
  800. 'If it finds a similar match then it displays the excess information in a highlighted format
  801. 'to the right of the cursor position. It also positions the Grid on the similar record.
  802. 'If there is a total nomatch then the code displays a small error box for a length of time
  803. 'determined by the Timer1 control. Then places the cursor in the previous position before the
  804. 'error occured.
  805. Dim CurLength As Integer
  806. Select Case KeyCode
  807.   Case 16
  808.     Exit Sub
  809.   'Filter the input
  810.   Case 32, 46, 48 To 57, 65 To 90, 96 To 122
  811.     With dbGridSource.Recordset
  812.       DoEvents
  813.       'See if you can locate in the database anything similar to the character or
  814.       'accumulation of characters contained in the 'txt' Textbox.
  815.       Criteria = dbGridSource.Recordset.Fields(0).Name & " like '" & txt & "*'"
  816.       .FindFirst Criteria
  817.       If .NoMatch Then  'Could'nt find it, so display the small error box.
  818.         DoEvents
  819.         Timer1.Enabled = True
  820.         lblError.Caption = "Not found in this database, Please try again."
  821.         lblError.Visible = True
  822.         If Len(txt) > 0 Then
  823.           'Adjust the text back to the last good input
  824.           txt = Mid(txt, 1, Len(txt) - 1)
  825.         End If
  826.       End If
  827.       CurLength = Len(txt)
  828.       If UCase(Left(txt, 1)) = UCase(Left(dbGridSource.Recordset.Fields(0), 1)) Then
  829.         'We have a similar match, so display it
  830.         txt = dbGridSource.Recordset.Fields(0)
  831.       End If
  832.       'Highlight everything to the right of the cursor position
  833.       SendKeys "{Home}", True
  834.       For I = 1 To CurLength
  835.         SendKeys "{Right}", True
  836.       Next I
  837.       SendKeys "+{End}", True
  838.     End With
  839. End Select
  840. End Sub
  841. Private Sub txt_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  842. 'If Right mouse button the show menu.
  843. If Button = 2 Then
  844.   PopupMenu mnuOptions
  845. End If
  846. End Sub
  847. Private Sub txtPath_KeyDown(KeyCode As Integer, Shift As Integer)
  848. Select Case KeyCode
  849.   Case vbKeyReturn
  850.     'Have the code click the 'Refresh' button.
  851.     cmdRefresh_Click
  852. End Select
  853. End Sub
  854. Private Sub txtPath_KeyPress(KeyAscii As Integer)
  855. Select Case KeyAscii
  856.   Case vbKeyReturn, vbKeyEscape
  857.     'Dont let the system beep when you press the 'Enter' key.
  858.     KeyAscii = 0
  859. End Select
  860. End Sub
  861. Private Sub txtPath_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  862. 'If Right mouse button the show menu.
  863. If Button = 2 Then
  864.   PopupMenu mnuOptions
  865. End If
  866. End Sub
  867.