home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 5.00 Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX" Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" Begin VB.Form frmDBGrid Caption = "Records" ClientHeight = 4950 ClientLeft = 60 ClientTop = 345 ClientWidth = 8595 Icon = "DBGrid.frx":0000 LinkTopic = "Form1" MDIChild = -1 'True ScaleHeight = 4950 ScaleWidth = 8595 Begin VB.PictureBox pbx2 Height = 375 Left = 360 ScaleHeight = 315 ScaleWidth = 765 TabIndex = 16 Top = 4410 Width = 825 Begin VB.CommandButton cmdSearch Caption = "Search" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = 0 TabIndex = 17 Top = 0 Width = 780 End End Begin VB.PictureBox pbx1 Height = 405 Left = 360 ScaleHeight = 345 ScaleWidth = 6825 TabIndex = 1 Top = 3870 Width = 6885 Begin VB.CommandButton cmdChange Caption = "Change" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 3330 TabIndex = 18 Top = 0 Width = 870 End Begin VB.CommandButton cmdFieldProperties Appearance = 0 'Flat BackColor = &H00C0E0FF& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 1320 Style = 1 'Graphical TabIndex = 15 ToolTipText = "Field properties" Top = 0 Width = 240 End Begin VB.CommandButton cmdRSProperties Appearance = 0 'Flat BackColor = &H00FFFFC0& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 1080 Style = 1 'Graphical TabIndex = 14 ToolTipText = "Recordset properties" Top = 0 Width = 240 End Begin VB.CommandButton cmdRSSupports Appearance = 0 'Flat BackColor = &H80000018& BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 840 Style = 1 'Graphical TabIndex = 12 ToolTipText = "Recordset supports" Top = 0 Width = 240 End Begin VB.CommandButton cmdRefresh Caption = "Refresh" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 0 TabIndex = 11 Top = 0 Width = 825 End Begin VB.CommandButton cmdAdd Caption = "Add" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 1560 TabIndex = 6 Top = 0 Width = 915 End Begin VB.CommandButton cmdDelete Caption = "Delete" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 2460 TabIndex = 5 Top = 0 Width = 870 End Begin VB.CommandButton cmdClose Caption = "Close" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 5940 TabIndex = 4 Top = 0 Width = 870 End Begin VB.CommandButton cmdSave Caption = "Save" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 5070 TabIndex = 3 Top = 0 Width = 870 End Begin VB.CommandButton cmdAbort Caption = "Abort" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 345 Left = 4200 TabIndex = 2 Top = 0 Width = 870 End End Begin MSDataGridLib.DataGrid DataGrid1 Height = 3030 Left = 315 TabIndex = 0 Top = 765 Width = 7800 _ExtentX = 13758 _ExtentY = 5345 _Version = 393216 AllowUpdate = -1 'True AllowArrows = -1 'True HeadLines = 1 RowHeight = 15 AllowAddNew = -1 'True AllowDelete = -1 'True BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ColumnCount = 2 BeginProperty Column00 DataField = "" Caption = "" BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} Type = 0 Format = "" HaveTrueFalseNull= 0 FirstDayOfWeek = 0 FirstWeekOfYear = 0 LCID = 1033 SubFormatType = 0 EndProperty EndProperty BeginProperty Column01 DataField = "" Caption = "" BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} Type = 0 Format = "" HaveTrueFalseNull= 0 FirstDayOfWeek = 0 FirstWeekOfYear = 0 LCID = 1033 SubFormatType = 0 EndProperty EndProperty SplitCount = 1 BeginProperty Split0 AllowSizing = 0 'False BeginProperty Column00 EndProperty BeginProperty Column01 EndProperty EndProperty End Begin VB.PictureBox pbx3 Height = 375 Left = 1215 ScaleHeight = 315 ScaleWidth = 720 TabIndex = 9 Top = 4410 Width = 780 Begin VB.CommandButton cmdFields Caption = "Fields" Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 330 Left = -45 TabIndex = 10 Top = 0 Width = 780 End End Begin MSAdodcLib.Adodc Adodc1 Height = 375 Left = 3660 Top = 4410 Width = 1935 _ExtentX = 3413 _ExtentY = 661 ConnectMode = 3 CursorLocation = 3 IsolationLevel = -1 ConnectionTimeout= 15 CommandTimeout = 30 CursorType = 3 LockType = 3 CommandType = 8 CursorOptions = 0 CacheSize = 50 MaxRecords = 0 BOFAction = 0 EOFAction = 0 ConnectStringType= 1 Appearance = 1 BackColor = -2147483643 ForeColor = -2147483640 Orientation = 0 Enabled = -1 Connect = "" OLEDBString = "" OLEDBFile = "" DataSourceName = "" OtherAttributes = "" UserName = "" Password = "" RecordSource = "" Caption = "Adodc1" BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty _Version = 393216 End Begin VB.Label lblrecordcount BorderStyle = 1 'Fixed Single BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 5700 TabIndex = 13 Top = 4410 Width = 1515 End Begin VB.Label lblTable Caption = "lblTable" Height = 240 Left = 360 TabIndex = 8 Top = 450 Width = 6810 End Begin VB.Label lblDatabase Caption = "lblDatabase" Height = 285 Left = 360 TabIndex = 7 Top = 180 Width = 6900 End Attribute VB_Name = "frmDBGrid" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' DBGrid.frm ' By Herman Liu Option Explicit Dim WithEvents rs As adodb.Recordset Attribute rs.VB_VarHelpID = -1 Dim mbookmark As Variant Dim mreccount As Integer Dim mNoRowSetYet As Boolean Private Sub Form_Load() On Error GoTo errhandler mNoRowSetYet = True ' Show a dummy default first, in case error would occur Adodc1.Caption = "0" Set rs = New Recordset Me.lblDatabase = "Database: " + gFileSpec Me.lblTable = "Table: " + gTableName rs.Open "select * from [" & gTableName & "]", gAcnn, adOpenStatic, adLockOptimistic If rs.EOF Then mreccount = 0 MsgBox "No record in table" Exit Sub End If Set Adodc1.Recordset = rs Set DataGrid1.DataSource = rs ' Make sure edit of cells is NOT allowed DataGrid1.Splits(0).Locked = True ' Disallow splits of grid DataGrid1.Splits(0).AllowSizing = False DataGrid1.Splits(0).AllowFocus = True DataGrid1.Splits(0).AllowRowSizing = True DataGrid1.Splits(0).RecordSelectors = True DataGrid1.Refresh Dim i As Integer, j As Integer Dim mfldcount Dim k As Boolean Dim s As String rs.MoveLast rs.MoveFirst mreccount = rs.RecordCount Me.lblrecordcount = "Total: " & mreccount mfldcount = rs.Fields.Count ' We exclude adVarBinary (type=204), adlongVarBinary (205) ' adBinary (type=128) types of fields in the grid and ' adBSTR (type=8). ' Identify the subscript position in gstrFieldsOrig() for the current ' table. gstrFields and gstrFieldsOrig are same size. ' As form is being loaded, cannot call GetSubscript() yet, refer value ' of gTableName instead. Dim msubscript As Integer j = 0 For i = 0 To UBound(gstrFieldsOrig) - 1 s = gstrFieldsOrig(i, 1) If s = gTableName Then Exit For End If j = j + 1 Next msubscript = j gstrFieldsOrig(msubscript, 2) = "" k = False For i = 0 To mfldcount - 1 ' In order not to mistaken, e.g "5" as "205", in gconExcludeFieldTypes, uniform 3-digit s = rs.Fields(i).Type If Len(s) < 3 Then s = s & "XX" End If If InStr(gconexcludeFieldTypes, s) <> 0 Then DataGrid1.Columns(i).Visible = False k = True Else ' Get a copy for gstrFieldsOrig for use in cmdFields gstrFieldsOrig(msubscript, 2) = gstrFieldsOrig(msubscript, 2) & rs.Fields(i).Name & "," End If Next i ' Don't get rid of last "," for gstrFieldsorig; it just serves the purpose If k = True Then Me.Caption = "Records: [Binary field(s) excluded]" End If ' There is a rowset to highlight now mNoRowSetYet = False ' Hightlight first row of Datagrid. DataGrid1.SelBookmarks.Add rs.Bookmark Adodc1.Caption = CStr(rs.AbsolutePosition) ' Disable record edit buttons cmdAdd.Enabled = False cmdDelete.Enabled = False cmdChange.Enabled = False cmdAbort.Enabled = False cmdSave.Enabled = False cmdRefresh.Enabled = False ' Since query can have link relationship, don't allow selection ' of individual fields Exit Sub errhandler: mreccount = 0 ErrMsgProc "frmDBGrid Form_load. Failed to establish a connection" End Sub Private Sub Form_Resize() If Me.WindowState = vbMinimized Then Exit Sub End If DataGrid1.Width = Me.Width - 800 DataGrid1.Height = Me.Height - 2600 pbx1.Top = (DataGrid1.Top + DataGrid1.Height) + 200 Adodc1.Top = (pbx1.Top + pbx1.Height) + 200 lblrecordcount.Top = Adodc1.Top pbx2.Top = Adodc1.Top pbx3.Top = Adodc1.Top End Sub Private Sub Form_Unload(Cancel As Integer) On Error Resume Next rs.Close Set rs = Nothing Exit Sub End Sub ' Here this event procedure is for highlight of current record Private Sub Adodc1_MoveComplete(ByVal adReason As adodb.EventReasonEnum, ByVal pError As adodb.Error, adStatus As adodb.EventStatusEnum, ByVal pRecordset As adodb.Recordset) On Error GoTo errhandler If mNoRowSetYet Then Exit Sub End If ' Avoid user going too far at both ends If rs.BOF Or rs.EOF() Then Exit Sub End If If mreccount > 0 Then Adodc1.Caption = CStr(rs.AbsolutePosition) ' Remove all highlights first Do While DataGrid1.SelBookmarks.Count > 0 DataGrid1.SelBookmarks.Remove 0 Loop ' Highlight the current row DataGrid1.SelBookmarks.Add rs.Bookmark Else Adodc1.Caption = "0" End If Exit Sub errhandler: ErrMsgProc "frmDBGrid Adodc1_Movecomplete" End Sub Private Sub cmdRSSupports_Click() If mreccount = 0 Then MsgBox "No record in table" Exit Sub End If Dim mStrYes As String, mStrNo As String mStrYes = "": mStrNo = "" If (rs.Supports(adAddNew)) Then mStrYes = mStrYes & " adAddNew" & vbCrLf Else mStrNo = mStrNo & " adAddNew" & vbCrLf End If If rs.Supports(adDelete) Then mStrYes = mStrYes & " adDelete" & vbCrLf Else mStrNo = mStrNo & " adDelete" & vbCrLf End If If rs.Supports(adUpdate) Then mStrYes = mStrYes & " adUpdate" & vbCrLf Else mStrNo = mStrNo & " adUpdate" & vbCrLf End If If rs.Supports(adUpdateBatch) Then mStrYes = mStrYes & " adUpdateBatch" & vbCrLf Else mStrNo = mStrNo & " adUpdateBatch" & vbCrLf End If If rs.Supports(adResync) Then mStrYes = mStrYes & " adResync" & vbCrLf Else mStrNo = mStrNo & " adResync" & vbCrLf End If If rs.Supports(adBookmark) Then mStrYes = mStrYes & " adBookmark" & vbCrLf Else mStrNo = mStrNo & " adBookmark" & vbCrLf End If If rs.Supports(adApproxPosition) Then mStrYes = mStrYes & " adApproxPosition" & vbCrLf Else mStrNo = mStrNo & " adApproxPosition" & vbCrLf End If If rs.Supports(adMovePrevious) Then mStrYes = mStrYes & " adMovePrevious" & vbCrLf Else mStrNo = mStrNo & " adMovePrevious" & vbCrLf End If MsgBox "Following are supported:" & vbCrLf & mStrYes & vbCrLf & _ "Following are not supported:" & vbCrLf & mStrNo & vbCrLf End Sub Private Sub cmdRSProperties_Click() If mreccount = 0 Then MsgBox "No record in table" Exit Sub End If Dim c As String, l As String Dim e As String, s As String, t As String c = Space(2) & ConvCursorType(rs.CursorType) l = Space(2) & ConvLockType(rs.LockType) e = ConvEditMode(rs.EditMode) s = ConvState(rs.State) t = ConvStatus(rs.Status) MsgBox "CursorType:" & vbCrLf & c & vbCrLf & vbCrLf & _ "LockType: " & vbCrLf & l & vbCrLf & vbCrLf & _ "Current state and status:" & vbCrLf & _ " EditMode: " & e & vbCrLf & _ " State: " & s & vbCrLf & _ " Status: " & t & vbCrLf End Sub ' Display similar field properties as in frmTablesTVW Private Sub cmdFieldProperties_Click() If mreccount = 0 Then MsgBox "No record in table" Exit Sub End If Dim mthisFldName As String Dim mType As Long Dim mAttr Dim mstrType As String Dim mstrAttr As String Dim mDefinedSize Dim mNumericScale Dim mPrecision ' Relying on current column caption to get field name mthisFldName = DataGrid1.Columns(DataGrid1.Col).Caption mType = rs.Fields(mthisFldName).Type mstrType = ConvType(mType) mAttr = rs.Fields(mthisFldName).Attributes mstrAttr = ConvAttr(mAttr) mDefinedSize = rs.Fields(mthisFldName).DefinedSize mNumericScale = rs.Fields(mthisFldName).NumericScale mPrecision = rs.Fields(mthisFldName).Precision MsgBox "Field properties:" & vbCrLf & _ " Name: " & mthisFldName & vbCrLf & _ " Type: " & mstrType & vbCrLf & _ " Attributes: " & mstrAttr & vbCrLf & _ " DefinedSize: " & mDefinedSize & vbCrLf & _ " NumericScale: " & mNumericScale & vbCrLf & _ " Precision: " & mPrecision & vbCrLf End Sub Private Sub cmdClose_Click() On Error Resume Next rs.Close Set rs = Nothing Unload Me End Sub