home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l405 / 4.ddi / DYNASET.FR_ / DYNASET.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  28.1 KB  |  945 lines

  1. VERSION 2.00
  2. Begin Form fDynaset 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3750
  5.    ClientLeft      =   1410
  6.    ClientTop       =   2415
  7.    ClientWidth     =   5655
  8.    Height          =   4155
  9.    Icon            =   DYNASET.FRX:0000
  10.    KeyPreview      =   -1  'True
  11.    Left            =   1350
  12.    LinkTopic       =   "Form1"
  13.    MDIChild        =   -1  'True
  14.    ScaleHeight     =   3733.906
  15.    ScaleMode       =   0  'User
  16.    ScaleWidth      =   5675.317
  17.    Tag             =   "Dynaset"
  18.    Top             =   2070
  19.    Width           =   5775
  20.    Begin PictureBox FieldHeader 
  21.       BackColor       =   &H00C0C0C0&
  22.       BorderStyle     =   0  'None
  23.       Height          =   240
  24.       Left            =   0
  25.       ScaleHeight     =   240
  26.       ScaleMode       =   0  'User
  27.       ScaleWidth      =   5028
  28.       TabIndex        =   16
  29.       Top             =   480
  30.       Width           =   5025
  31.       Begin Label FieldValueLabel 
  32.          BackColor       =   &H00C0C0C0&
  33.          Caption         =   " Value  (F4=Zoom) "
  34.          Height          =   255
  35.          Left            =   1680
  36.          TabIndex        =   18
  37.          Top             =   0
  38.          Width           =   3165
  39.       End
  40.       Begin Label FieldHdrLabel 
  41.          BackColor       =   &H00C0C0C0&
  42.          Caption         =   "Field Name:"
  43.          Height          =   252
  44.          Left            =   120
  45.          TabIndex        =   17
  46.          Top             =   0
  47.          Width           =   1212
  48.       End
  49.    End
  50.    Begin PictureBox ViewButtons 
  51.       Align           =   1  'Align Top
  52.       BackColor       =   &H00C0C0C0&
  53.       BorderStyle     =   0  'None
  54.       Height          =   495
  55.       Left            =   0
  56.       ScaleHeight     =   495
  57.       ScaleMode       =   0  'User
  58.       ScaleWidth      =   5658.376
  59.       TabIndex        =   0
  60.       Top             =   0
  61.       Width           =   5655
  62.       Begin CommandButton SortButton 
  63.          Caption         =   "&Sort"
  64.          Height          =   330
  65.          Left            =   3128
  66.          TabIndex        =   24
  67.          Top             =   0
  68.          Width           =   650
  69.       End
  70.       Begin CommandButton FilterButton 
  71.          Caption         =   "F&ilter"
  72.          Height          =   330
  73.          Left            =   2520
  74.          TabIndex        =   23
  75.          Top             =   0
  76.          Width           =   650
  77.       End
  78.       Begin CommandButton CloseButton 
  79.          Cancel          =   -1  'True
  80.          Caption         =   "&Close"
  81.          Height          =   330
  82.          Left            =   4367
  83.          TabIndex        =   9
  84.          TabStop         =   0   'False
  85.          Top             =   0
  86.          Width           =   650
  87.       End
  88.       Begin CommandButton PropButton 
  89.          Caption         =   "&Prop"
  90.          Height          =   330
  91.          Left            =   3738
  92.          TabIndex        =   5
  93.          Top             =   0
  94.          Width           =   650
  95.       End
  96.       Begin CommandButton DelButton 
  97.          Caption         =   "&Del"
  98.          Height          =   330
  99.          Left            =   1260
  100.          TabIndex        =   4
  101.          Top             =   0
  102.          Width           =   650
  103.       End
  104.       Begin CommandButton EditButton 
  105.          Caption         =   "&Edit"
  106.          Height          =   330
  107.          Left            =   630
  108.          TabIndex        =   3
  109.          Top             =   0
  110.          Width           =   650
  111.       End
  112.       Begin CommandButton AddButton 
  113.          Caption         =   "&Add"
  114.          Height          =   330
  115.          Left            =   0
  116.          TabIndex        =   2
  117.          Top             =   0
  118.          Width           =   650
  119.       End
  120.       Begin CommandButton FindButton 
  121.          Caption         =   "&Find"
  122.          Height          =   330
  123.          Left            =   1890
  124.          TabIndex        =   1
  125.          Top             =   0
  126.          Width           =   650
  127.       End
  128.    End
  129.    Begin PictureBox ChangeButtons 
  130.       BackColor       =   &H00C0C0C0&
  131.       BorderStyle     =   0  'None
  132.       Height          =   480
  133.       Left            =   0
  134.       ScaleHeight     =   480
  135.       ScaleMode       =   0  'User
  136.       ScaleWidth      =   5028
  137.       TabIndex        =   6
  138.       Top             =   0
  139.       Visible         =   0   'False
  140.       Width           =   5028
  141.       Begin CommandButton UpdateButton 
  142.          Caption         =   "&Update"
  143.          Height          =   372
  144.          Left            =   960
  145.          TabIndex        =   8
  146.          Top             =   48
  147.          Width           =   1212
  148.       End
  149.       Begin CommandButton CancelButton 
  150.          Caption         =   "&Cancel"
  151.          Height          =   372
  152.          Left            =   2640
  153.          TabIndex        =   7
  154.          Top             =   48
  155.          Width           =   1212
  156.       End
  157.    End
  158.    Begin PictureBox StatBox 
  159.       Align           =   2  'Align Bottom
  160.       BackColor       =   &H00C0C0C0&
  161.       BorderStyle     =   0  'None
  162.       Height          =   281
  163.       Left            =   0
  164.       ScaleHeight     =   298.153
  165.       ScaleMode       =   0  'User
  166.       ScaleWidth      =   5665.189
  167.       TabIndex        =   14
  168.       Top             =   3465
  169.       Width           =   5655
  170.       Begin CommandButton NextButton 
  171.          Caption         =   ">"
  172.          FontBold        =   -1  'True
  173.          FontItalic      =   0   'False
  174.          FontName        =   "MS Sans Serif"
  175.          FontSize        =   12
  176.          FontStrikethru  =   0   'False
  177.          FontUnderline   =   0   'False
  178.          Height          =   287
  179.          Left            =   4200
  180.          TabIndex        =   22
  181.          Top             =   0
  182.          Width           =   375
  183.       End
  184.       Begin CommandButton LastButton 
  185.          Caption         =   ">|"
  186.          FontBold        =   -1  'True
  187.          FontItalic      =   0   'False
  188.          FontName        =   "MS Sans Serif"
  189.          FontSize        =   12
  190.          FontStrikethru  =   0   'False
  191.          FontUnderline   =   0   'False
  192.          Height          =   287
  193.          Left            =   4575
  194.          TabIndex        =   21
  195.          Top             =   0
  196.          Width           =   375
  197.       End
  198.       Begin CommandButton FirstButton 
  199.          Caption         =   "|<"
  200.          FontBold        =   -1  'True
  201.          FontItalic      =   0   'False
  202.          FontName        =   "MS Sans Serif"
  203.          FontSize        =   12
  204.          FontStrikethru  =   0   'False
  205.          FontUnderline   =   0   'False
  206.          Height          =   287
  207.          Left            =   0
  208.          TabIndex        =   20
  209.          Top             =   0
  210.          Width           =   375
  211.       End
  212.       Begin CommandButton PrevButton 
  213.          Caption         =   "<"
  214.          FontBold        =   -1  'True
  215.          FontItalic      =   0   'False
  216.          FontName        =   "MS Sans Serif"
  217.          FontSize        =   12
  218.          FontStrikethru  =   0   'False
  219.          FontUnderline   =   0   'False
  220.          Height          =   287
  221.          Left            =   375
  222.          TabIndex        =   19
  223.          Top             =   0
  224.          Width           =   375
  225.       End
  226.       Begin Label cStatusBar 
  227.          BackColor       =   &H00FFFFFF&
  228.          BorderStyle     =   1  'Fixed Single
  229.          Height          =   287
  230.          Left            =   749
  231.          TabIndex        =   15
  232.          Top             =   5
  233.          Width           =   3360
  234.       End
  235.    End
  236.    Begin VScrollBar cScrollBar 
  237.       Height          =   2616
  238.       LargeChange     =   3000
  239.       Left            =   5040
  240.       SmallChange     =   300
  241.       TabIndex        =   13
  242.       Top             =   720
  243.       Visible         =   0   'False
  244.       Width           =   252
  245.    End
  246.    Begin PictureBox cFields 
  247.       BackColor       =   &H00C0C0C0&
  248.       BorderStyle     =   0  'None
  249.       Height          =   375
  250.       Left            =   120
  251.       ScaleHeight     =   372
  252.       ScaleMode       =   0  'User
  253.       ScaleWidth      =   4812
  254.       TabIndex        =   10
  255.       Top             =   720
  256.       Width           =   4815
  257.       Begin TextBox cFieldData 
  258.          BackColor       =   &H00FFFFFF&
  259.          DataSource      =   "Data1"
  260.          ForeColor       =   &H00000000&
  261.          Height          =   288
  262.          Index           =   0
  263.          Left            =   1560
  264.          TabIndex        =   11
  265.          Top             =   0
  266.          Visible         =   0   'False
  267.          Width           =   3252
  268.       End
  269.       Begin Label cFieldName 
  270.          BackColor       =   &H00C0C0C0&
  271.          ForeColor       =   &H00000000&
  272.          Height          =   252
  273.          Index           =   0
  274.          Left            =   0
  275.          TabIndex        =   12
  276.          Top             =   60
  277.          Visible         =   0   'False
  278.          Width           =   1572
  279.       End
  280.    End
  281. Option Explicit
  282. 'form variables
  283. Dim FDS As dynaset            'current form's dynaset
  284. Dim FTblName As String        'form dynaset table name
  285. Dim FBM As String             'form bookmark
  286. Dim FNotFound As Integer      'used by find function
  287. Dim FAtTop As Integer         'top flag
  288. Dim FEditFlag As Integer      'edit mode
  289. Dim FAddNewFlag As Integer    'add mode
  290. Dim FFldDataChanged As Integer
  291. Dim FFindForm As New fFind    'find form instance
  292. Dim FCurrRec As Integer       'record counter
  293. Dim FNumbRows As Long         'total rows in dynaset
  294. Dim FDynaString As String     'dynaset open string
  295. Sub AddButton_Click ()
  296.   On Error GoTo AddErr
  297.   'set the mode
  298.   FDS.AddNew
  299.   cStatusBar = "Add record"
  300.   FAddNewFlag = True
  301.   If FDS.RecordCount > 0 Then
  302.     FBM = FDS.Bookmark
  303.   Else
  304.     FBM = ""
  305.   End If
  306.   ChangeButtons.Visible = True
  307.   ViewButtons.Visible = False
  308.   NextButton.Enabled = False
  309.   FirstButton.Enabled = False
  310.   LastButton.Enabled = False
  311.   PrevButton.Enabled = False
  312.   ClearDataFields
  313.   cFieldData(0).SetFocus
  314.   GoTo AddEnd
  315. AddErr:
  316.   ShowError
  317.   Resume AddEnd
  318. AddEnd:
  319. End Sub
  320. Sub CancelButton_Click ()
  321.    On Error Resume Next
  322.    ChangeButtons.Visible = False
  323.    ViewButtons.Visible = True
  324.    NextButton.Enabled = True
  325.    FirstButton.Enabled = True
  326.    LastButton.Enabled = True
  327.    PrevButton.Enabled = True
  328.    FEditFlag = False
  329.    FAddNewFlag = False
  330.    If FBM <> "" Then FDS.Bookmark = FBM
  331.    DisplayCurrentRecord
  332. End Sub
  333. Sub cFieldData_Change (Index As Integer)
  334.   'just set the flag if data is changed
  335.   'it gets reset to false when a new record is displayed
  336.   FFldDataChanged = True
  337. End Sub
  338. Sub cFieldData_KeyDown (Index As Integer, KeyCode As Integer, Shift As Integer)
  339.   If KeyCode = &H73 Then   'F4
  340.     cFieldName_DblClick Index
  341.   ElseIf KeyCode = 34 And cScrollBar.Visible = True Then
  342.     'pagedown with > 10 fields
  343.     cScrollBar = cScrollBar - 3000
  344.   ElseIf KeyCode = 33 And cScrollBar.Visible = True Then
  345.     'pageup with > 10 fields
  346.     cScrollBar = cScrollBar + 3000
  347.   End If
  348. End Sub
  349. Sub cFieldData_KeyPress (Index As Integer, KeyAscii As Integer)
  350.   'only allow return when in edit of add mode
  351.   If FEditFlag = True Or FAddNewFlag = True Then
  352.     If FDS(Index).Type = FT_STRING And Len(cFieldData(Index)) > FDS(Index).Size Then
  353.       Beep
  354.       MsgBox "Field Length Exceeded!", 48
  355.       KeyAscii = 0
  356.       Exit Sub
  357.     End If
  358.     If KeyAscii = 13 Then
  359.       KeyAscii = 0
  360.       SendKeys "{Tab}"
  361.     End If
  362.   'throw away the keystrokes if not in add or edit mode
  363.   ElseIf FEditFlag = False And FAddNewFlag = False Then
  364.     KeyAscii = 0
  365.   End If
  366. End Sub
  367. Sub cFieldData_LostFocus (Index As Integer)
  368.   On Error GoTo FldDataErr
  369.   If FFldDataChanged = True Then
  370.     'store the data in the field
  371.     FDS(Index) = cFieldData(Index)
  372.   End If
  373.   GoTo FldDataEnd
  374. FldDataErr:
  375.   ShowError
  376.   Resume FldDataEnd
  377. FldDataEnd:
  378.   'reset for valid or error condition
  379.   FFldDataChanged = False
  380. End Sub
  381. Sub cFieldName_DblClick (Index As Integer)
  382.   On Error GoTo ZoomErr
  383.   If FDS(Index).Type = FT_STRING Or FDS(Index).Type = FT_MEMO Then
  384.      If FDS(Index).FieldSize() < GETCHUNK_CUTOFF Then
  385.        gstZoomData = cFieldData(Index)
  386.      Else
  387.        'add the rest of the field data with getchunk
  388.        MsgBar "Getting Memo Field Data", True
  389.        SetHourglass Me
  390.        gstZoomData = cFieldData(Index) + StripNonAscii(FDS(Index).GetChunk(GETCHUNK_CUTOFF, MAX_MEMO_SIZE))
  391.        ResetMouse Me
  392.        MsgBar "", False
  393.      End If
  394.      fZoom.Caption = Mid(cFieldName(Index), 1, Len(cFieldName(Index)) - 1)
  395.      fZoom.Top = Top + 1200
  396.      fZoom.Left = Left + 250
  397.      If FAddNewFlag Or FEditFlag Then
  398.        fZoom.SaveButton.Visible = True
  399.        fZoom.CloseButton.Visible = True
  400.      Else
  401.        fZoom.CloseZoomButton.Visible = True
  402.      End If
  403.      fZoom.Show MODAL
  404.      If FAddNewFlag Or FEditFlag Then
  405.        If FDS(Index).Type = FT_STRING And Len(gstZoomData) > FDS(Index).Size Then
  406.          Beep
  407.          MsgBox "Field Length Exceeded, Data Truncated!", 48
  408.          cFieldData(Index) = Mid(gstZoomData, 1, FDS(Index).Size)
  409.        Else
  410.          cFieldData(Index) = gstZoomData
  411.        End If
  412.        FDS(Index) = cFieldData(Index)
  413.        FFldDataChanged = False
  414.      End If
  415.   End If
  416.   GoTo ZoomEnd
  417. ZoomErr:
  418.   ShowError
  419.   Resume ZoomEnd
  420. ZoomEnd:
  421. End Sub
  422. Sub ClearDataFields ()
  423.   Dim i As Integer
  424.   'clear out the fields on the main form
  425.   For i = 0 To FDS.Fields.Count - 1
  426.     cFieldData(i) = ""
  427.   Next
  428. End Sub
  429. Sub CloseButton_Click ()
  430.   Unload Me
  431. End Sub
  432. Sub cScrollBar_Change ()
  433.   Dim t As Integer
  434.   t = cScrollBar
  435.   If (t - 720) Mod 300 = 0 Then
  436.     cFields.Top = t
  437.   Else
  438.     cFields.Top = ((t - 720) \ 300) * 300 + 720
  439.   End If
  440. End Sub
  441. Sub DelButton_Click ()
  442.   On Error GoTo DelRecErr
  443.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  444.     FDS.Delete
  445.     If gfTransPending Then gfDBChanged = True
  446.     If FDS.EOF = False Then
  447.       FDS.MoveNext
  448.     End If
  449.     FNumbRows = FNumbRows - 1
  450.     DisplayCurrentRecord
  451.   End If
  452.   GoTo DelRecEnd
  453. DelRecErr:
  454.   ShowError
  455.   Resume DelRecEnd
  456. DelRecEnd:
  457. End Sub
  458. Sub DisplayCurrentRecord ()
  459.    Dim i As Integer
  460.    Dim cst As String    'current status bar
  461.    On Error GoTo DCRErr
  462.    SetHourglass Me
  463.    cst = "Record "
  464.    'check BOF/EOF flag so we know if we
  465.    'are sitting on a valid record
  466.    If FAddNewFlag = True Then
  467.      cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  468.    Else
  469.      If FDS.BOF = True Then
  470.        cst = cst + "(BOF) of " + CStr(FNumbRows)
  471.        ClearDataFields
  472.      ElseIf FDS.EOF = True Then
  473.        cst = cst + "(EOF) of " + CStr(FNumbRows)
  474.        ClearDataFields
  475.      Else
  476.        cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  477.        'place the data in the form fields
  478.        For i = 0 To FDS.Fields.Count - 1
  479.          If FDS(i).Type = FT_MEMO Then
  480.            If FDS(i).FieldSize() < GETCHUNK_CUTOFF Then
  481.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  482.            Else
  483.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i).GetChunk(0, GETCHUNK_CUTOFF)))
  484.            End If
  485.          ElseIf FDS(i).Type = FT_STRING Then
  486.            cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  487.          Else
  488.            cFieldData(i) = vFieldVal(FDS(i))
  489.          End If
  490.        Next
  491.      End If
  492.    End If
  493.    If gfUpdatable = False Then cst = cst + "  [Not Updatable]"
  494.    cStatusBar = cst
  495.    'set the flag
  496.    FFldDataChanged = False
  497.    GoTo DCREnd
  498. DCRErr:
  499.   ShowError
  500.   Resume DCREnd
  501. DCREnd:
  502.    ResetMouse Me
  503. End Sub
  504. Sub EditButton_Click ()
  505.    On Error GoTo EditErr
  506.    FDS.Edit
  507.    cStatusBar = "Edit record"
  508.    FEditFlag = True
  509.    cFieldData(0).SetFocus
  510.    FBM = FDS.Bookmark
  511.    ChangeButtons.Visible = True
  512.    ViewButtons.Visible = False
  513.    NextButton.Enabled = False
  514.    FirstButton.Enabled = False
  515.    LastButton.Enabled = False
  516.    PrevButton.Enabled = False
  517.    GoTo EditEnd
  518. EditErr:
  519.   ShowError
  520.   Resume EditEnd
  521. EditEnd:
  522. End Sub
  523. Sub FilterButton_Click ()
  524.   On Error GoTo FilterErr
  525.   Dim bm As String
  526.   Dim ds1 As dynaset, ds2 As dynaset
  527.   Dim FilterStr As String
  528.   bm = FDS.Bookmark        'save the bookmark
  529.   Set ds1 = FDS            'save the dynaset
  530.   FilterStr = InputBox("Enter Filter Expression:")
  531.   If FilterStr = "" Then Exit Sub
  532.   SetHourglass Me
  533.   MsgBar "Setting New Filter", True
  534.   FDS.Filter = FilterStr
  535.   Set ds2 = FDS.CreateDynaset()            'establish the filter
  536.   Set FDS = ds2            'assign back to original dynaset object
  537.   'everything must be okay so redisplay form on 1st record
  538.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  539.   FCurrRec = 1
  540.   DisplayCurrentRecord     'display field values
  541.   FAtTop = True
  542.   ResetMouse Me
  543.   MsgBar "", False
  544.   GoTo FilterEnd
  545. FilterErr:
  546.   ResetMouse Me
  547.   MsgBar "", False
  548.   ShowError
  549.   Set FDS = ds1            're-assign back to original
  550.   FDS.Bookmark = bm        'go back to original record
  551.   Resume FilterEnd
  552. FilterEnd:
  553. End Sub
  554. Sub FindButton_Click ()
  555.   Dim i As Integer
  556.   Dim bm As String
  557.   On Error GoTo FindErr
  558.   'load the column names into the find form
  559.   If FFindForm.cFieldList.ListCount = 0 Then
  560.     For i = 0 To FDS.Fields.Count - 1
  561.       FFindForm.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  562.     Next
  563.   End If
  564. FindStart:
  565.   'reset the flags
  566.   gfFindFailed = False
  567.   gfFromTableView = False
  568.   FNotFound = False
  569.   MsgBar "Enter Search Parameters", False
  570.   FFindForm.Show MODAL
  571.   MsgBar "Searching for New Record", True
  572.   If gfFindFailed = True Then   'find cancelled
  573.     GoTo AfterWhile
  574.   End If
  575.   SetHourglass Me
  576.    i = FFindForm.cFieldList.ListIndex
  577.    'search for the record
  578.    bm = FDS.Bookmark
  579.    If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  580.      FDS.FindFirst FDS(i).Name + " " + gstFindOp + " '" + gstFindExpr + "'"
  581.    Else
  582.      FDS.FindFirst FDS(i).Name + gstFindOp + gstFindExpr
  583.    End If
  584.    FNotFound = FDS.NoMatch
  585. AfterWhile:
  586.    ResetMouse Me
  587.    If gfFindFailed = True Then   'go back to top
  588.      FDS.Bookmark = bm
  589.    ElseIf FNotFound Then
  590.      Beep
  591.      MsgBox "Record Not Found", 48
  592.      FDS.Bookmark = bm
  593.      GoTo FindStart
  594.    Else
  595.      bm = FDS.Bookmark
  596.      FDS.MoveFirst
  597.      FCurrRec = 1
  598.      While FDS.Bookmark <> bm
  599.        FCurrRec = FCurrRec + 1
  600.        FDS.MoveNext
  601.      Wend
  602.    End If
  603.    DisplayCurrentRecord
  604.    GoTo FindEnd
  605. FindErr:
  606.    ResetMouse Me
  607.    If Err <> EOF_ERR Then
  608.      ShowError
  609.      Resume FindEnd
  610.    Else
  611.      FNotFound = True
  612.      Resume Next
  613.    End If
  614. FindEnd:
  615.    MsgBar "", False
  616. End Sub
  617. Sub FirstButton_Click ()
  618.    Dim ds As String
  619.    On Error GoTo GoFirstError
  620.    FDS.MoveFirst
  621.    FCurrRec = 1
  622.    DisplayCurrentRecord
  623.    FAtTop = True
  624.    GoTo GoFirstEnd
  625. GoFirstError:
  626.    ShowError
  627.    Resume GoFirstEnd
  628. GoFirstEnd:
  629.    ResetMouse Me
  630.    MsgBar "", False
  631. End Sub
  632. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  633.   If FEditFlag = True Or FAddNewFlag = True Then Exit Sub
  634.   Select Case KeyCode
  635.     Case 35                'end
  636.       Call LastButton_Click
  637.     Case 36                'home
  638.       Call FirstButton_Click
  639.     Case 38                'up arrow
  640.       If Shift = 2 Then
  641.         Call FirstButton_Click
  642.       Else
  643.         Call PrevButton_Click
  644.       End If
  645.     Case 40                'down arrow
  646.       If Shift = 2 Then
  647.         Call LastButton_Click
  648.       Else
  649.         Call NextButton_Click
  650.       End If
  651.     Case 114                'F3
  652.       Call FindButton_Click
  653.   End Select
  654. End Sub
  655. Sub Form_Load ()
  656.    Dim t As TableDef       'local table structure
  657.    Dim sp As Integer       'starting point of table name
  658.    Dim ep As Integer       'ending point of table name
  659.    Dim ds As String        'temp dynaset name string
  660.    Dim wh As String        'where clause
  661.    Dim ft As Integer
  662.    Dim i As Integer, j As Integer
  663.    Dim fn As String        'field name
  664.    Dim l As Long
  665.    Dim Start1, Finish1, Start2, Finish2
  666.    On Error GoTo DynasetErr
  667.    SetHourglass Me
  668.    MsgBar "Opening Dynaset", True
  669.    'disable match case checkbox on find form
  670.    'because it isn't implemented on this form
  671.    FFindForm.cMatchCase.Enabled = False
  672.    'assign the temp string with the select statement
  673.    'if it is not empty, otherwise, use the table list name
  674.    If gfFromSQL = True Then
  675.      If gstDynaString = "" Then
  676.        ds = fSQL.cSQLStatement
  677.      Else
  678.        ds = gstDynaString
  679.      End If
  680.    ElseIf gstTableDynaFilter <> "" Then
  681.      ds = gstTableDynaFilter
  682.    Else
  683.      ds = fTables.cTableList
  684.    End If
  685.    'attemp to open the dynaset
  686.    Start1 = Timer
  687.    If gfFromSQL = True And fSQL.cPassThru = 1 Then
  688.      Set FDS = gCurrentDB.CreateDynaset(ds, VBDA_SQLPASSTHROUGH)
  689.    Else
  690.      Set FDS = gCurrentDB.CreateDynaset(ds)
  691.    End If
  692.    Finish1 = Timer
  693.    Start2 = Timer
  694.    'parse off table name to store in global gstTblName
  695.    wh = ""
  696.    sp = InStr(1, UCase(ds), "FROM")
  697.    If sp > 0 Then
  698.      'must be a "select from" statement
  699.      sp = sp + 5
  700.      For ep = sp To Len(ds)
  701.        'search for a space or the end of ds
  702.        If Mid$(ds, ep, 1) = " " Then
  703.          'get where clause if there is one
  704.          wh = Mid$(ds, sp, Len(ds) - sp + 1)
  705.          Exit For
  706.        End If
  707.      Next
  708.      FTblName = UCase(Mid$(ds, sp, ep - sp))
  709.      If wh = "" Then wh = FTblName
  710.    Else
  711.      'must be a table name only
  712.      FTblName = UCase(ds)
  713.      wh = FTblName
  714.    End If
  715.    FDynaString = wh
  716.    'show the first record
  717.    FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  718.    'load the controls on the dynaset form
  719.    cFieldName(0).Visible = True
  720.    cFieldData(0).Visible = True
  721.    ft = FDS(0).Type
  722.    cFieldData(0).Width = GetFieldWidth(ft)
  723.    cFieldData(0).TabIndex = 0
  724.    For i = 1 To FDS.Fields.Count - 1
  725.      cFields.Height = cFields.Height + 300
  726.      Load cFieldName(i)
  727.      cFieldName(i).Top = cFieldName(i - 1).Top + 300
  728.      cFieldName(i).Visible = True
  729.      Load cFieldData(i)
  730.      cFieldData(i).Top = cFieldData(i - 1).Top + 300
  731.      cFieldData(i).Visible = True
  732.      ft = FDS.Fields(i).Type
  733.      cFieldData(i).Width = GetFieldWidth(ft)
  734.      cFieldData(i).TabIndex = i
  735.    Next
  736.    'resize main window
  737.    If i <= 10 Then
  738.      Height = ((i + 1) * 300) + 1400
  739.    Else
  740.      Height = 4368
  741.      Width = Width + 260
  742.      cScrollBar.Visible = True
  743.      cScrollBar.Min = 720
  744.      cScrollBar.Max = 720 - (i * 300) + 3000
  745.    End If
  746.    'display the field names
  747.    For i = 0 To FDS.Fields.Count - 1
  748.      cFieldName(i) = UCase(FDS(i).Name) + ":"
  749.    Next
  750.    FCurrRec = 1
  751.    DisplayCurrentRecord      'display field values
  752.    FAtTop = True
  753.    If gstTableDynaFilter <> "" Then
  754.      Caption = "Filtered Dynaset: " + FTblName
  755.    Else
  756.      Caption = "Dynaset: " + FTblName
  757.    End If
  758.    Width = 5805
  759.    Left = 1000
  760.    Top = 1000
  761.    Finish2 = Timer
  762.    If VDMDI.PrefShowPerf.Checked Then
  763.      Me.Show
  764.      MsgBox CStr(FNumbRows) + " rows found in " + CStr(Finish1 - Start1) + " seconds!" + Chr(13) + Chr(10) + CStr(Finish2 - Start2) + " seconds to Get Record Count!", 48
  765.    End If
  766.    GoTo OkayEnd
  767. DynasetErr:
  768.    ShowError
  769.    ResetMouse Me
  770.    Unload Me
  771.    MsgBar "", False
  772.    Exit Sub
  773.    Resume OkayEnd
  774. OkayEnd:
  775.    ResetMouse Me
  776.    MsgBar "", False
  777. End Sub
  778. Sub Form_Paint ()
  779.   Outlines Me
  780. End Sub
  781. Sub Form_Resize ()
  782.   On Error Resume Next
  783.   Dim h As Integer, i As Integer
  784.   Dim totw As Integer
  785.   If WindowState <> 1 Then   'not minimized
  786.     MsgBar "Resizing Form", True
  787.     'make sure the form is lined up on a field
  788.     h = Height
  789.     If (h - 1420) Mod 300 <> 0 Then
  790.       Height = ((h - 1420) \ 300) * 300 + 1420
  791.     End If
  792.     'resize the status bar
  793.     StatBox.Top = Height - 650
  794.     'resize the scrollbar
  795.     cScrollBar.Height = StatBox.Top - (ViewButtons.Top - FieldHeader.Height) - 960
  796.     cScrollBar.Left = Width - 360
  797.     If FDS.Fields.Count > 10 Then
  798.       cFields.Width = Width - 260
  799.       totw = cScrollBar.Left - 20
  800.     Else
  801.       cFields.Width = Width - 20
  802.       totw = Width - 50
  803.     End If
  804.     FieldHeader.Width = Width - 20
  805.     'widen the fields if possible
  806.     For i = 0 To FDS.Fields.Count - 1
  807.       cFieldName(i).Width = .3 * totw
  808.       cFieldData(i).Left = cFieldName(i).Width + 20
  809.       If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  810.         cFieldData(i).Width = .7 * totw - 250
  811.       End If
  812.     Next
  813.     FieldValueLabel.Left = cFieldData(0).Left
  814.     cStatusBar.Width = Width - 1600
  815.     NextButton.Left = cStatusBar.Width + 745
  816.     LastButton.Left = NextButton.Left + 370
  817.   End If
  818.   MsgBar "", False
  819. End Sub
  820. Sub Form_Unload (Cancel As Integer)
  821.   On Error Resume Next
  822.   Unload FFindForm   'get rid of attached find form
  823.   FDS.Close          'close the form dynaset
  824.   MsgBar "", False
  825. End Sub
  826. Sub LastButton_Click ()
  827.    On Error GoTo GoLastError
  828.    FDS.MoveLast
  829.    'show the current record
  830.    FCurrRec = FNumbRows
  831.    DisplayCurrentRecord
  832.    GoTo GoLastEnd
  833. GoLastError:
  834.    ShowError
  835.    Resume GoLastEnd
  836. GoLastEnd:
  837. End Sub
  838. Sub NextButton_Click ()
  839.    On Error GoTo GoNextError
  840.    FDS.MoveNext
  841.    'show the current record
  842.    FCurrRec = FCurrRec + 1   'bump the record counter
  843.    DisplayCurrentRecord
  844.    FAtTop = False
  845.    GoTo GoNextEnd
  846. GoNextError:
  847.    ShowError
  848.    Resume GoNextEnd
  849. GoNextEnd:
  850. End Sub
  851. Sub PrevButton_Click ()
  852.    On Error GoTo GoPrevError
  853.    FDS.MovePrevious
  854.    'show the current record
  855.    FCurrRec = FCurrRec - 1   'bump the record counter back
  856.    DisplayCurrentRecord
  857.    FAtTop = False
  858.    GoTo GoPrevEnd
  859. GoPrevError:
  860.    ShowError
  861.    Resume GoPrevEnd
  862. GoPrevEnd:
  863. End Sub
  864. Sub PropButton_Click ()
  865.    Dim f As New fDataBox
  866.    On Error GoTo DynPropErr
  867.    Set gCurrentDS = FDS
  868.    f.Caption = "Dynaset Properties"
  869.    f.Tag = "DS"
  870.    f.cData.AddItem "Name = " + FDS.Name
  871.    f.cData.AddItem "BOF Flag = " + stTrueFalse((FDS.BOF))
  872.    f.cData.AddItem "BookMark = " + FDS.Bookmark
  873.    f.cData.AddItem "BookMarkable Flag = " + stTrueFalse((FDS.Bookmarkable))
  874.    f.cData.AddItem "EOF Flag = " + stTrueFalse((FDS.EOF))
  875.    f.cData.AddItem "Filter = " + FDS.Filter
  876.    f.cData.AddItem "Last Modified = " + FDS.LastModified
  877.    f.cData.AddItem "Lock Edits Flag = " + stTrueFalse((FDS.LockEdits))
  878.    f.cData.AddItem "No Match Flag = " + stTrueFalse((FDS.NoMatch))
  879.    f.cData.AddItem "Sort = " + FDS.Sort
  880.    f.cData.AddItem "Transactions Flag = " + stTrueFalse((FDS.Transactions))
  881.    f.cData.AddItem "RecordCount = " & FDS.RecordCount
  882.    f.cData.AddItem "Updatable Flag = " + stTrueFalse((FDS.Updatable))
  883.    f.Show MODAL
  884.   GoTo DynPropEnd
  885. DynPropErr:
  886.   f.cData.AddItem Error$
  887.   Resume Next
  888. DynPropEnd:
  889. End Sub
  890. Sub SortButton_Click ()
  891.   On Error GoTo SortErr
  892.   Dim bm As String
  893.   Dim ds1 As dynaset, ds2 As dynaset
  894.   Dim SortStr As String
  895.   bm = FDS.Bookmark        'save the bookmark
  896.   Set ds1 = FDS            'save the dynaset
  897.   SortStr = InputBox("Enter Sort Column:")
  898.   If SortStr = "" Then Exit Sub
  899.   SetHourglass Me
  900.   MsgBar "Setting New Sort Order", True
  901.   FDS.Sort = SortStr
  902.   Set ds2 = FDS.CreateDynaset()            'establish the Sort
  903.   Set FDS = ds2            'assign back to original dynaset object
  904.   'everything must be okay so redisplay form on 1st record
  905.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  906.   FCurrRec = 1
  907.   DisplayCurrentRecord     'display field values
  908.   FAtTop = True
  909.   ResetMouse Me
  910.   MsgBar "", False
  911.   GoTo SortEnd
  912. SortErr:
  913.   ResetMouse Me
  914.   MsgBar "", False
  915.   ShowError
  916.   Set FDS = ds1            're-assign back to original
  917.   FDS.Bookmark = bm        'go back to original record
  918.   Resume SortEnd
  919. SortEnd:
  920. End Sub
  921. Sub UpdateButton_Click ()
  922.   On Error GoTo UpdateErr
  923.   FDS.Update
  924.   If gfTransPending Then gfDBChanged = True
  925.   If FAddNewFlag = True Then
  926.     FNumbRows = FNumbRows + 1
  927.     FCurrRec = FNumbRows
  928.     FDS.MoveLast             'move to the new record
  929.   End If
  930.   ChangeButtons.Visible = False
  931.   ViewButtons.Visible = True
  932.   NextButton.Enabled = True
  933.   FirstButton.Enabled = True
  934.   LastButton.Enabled = True
  935.   PrevButton.Enabled = True
  936.   FEditFlag = False
  937.   FAddNewFlag = False
  938.   DisplayCurrentRecord
  939.   GoTo UpdateEnd
  940. UpdateErr:
  941.   ShowError
  942.   Resume UpdateEnd
  943. UpdateEnd:
  944. End Sub
  945.