home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk4 / dynaset.fr_ / dynaset.bin
Text File  |  1993-04-28  |  29KB  |  1,112 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. End
  282. Option Explicit
  283.  
  284. 'form variables
  285. Dim FDS As dynaset            'current form's dynaset
  286. Dim FTblName As String        'form dynaset table name
  287. Dim FBM As String             'form bookmark
  288. Dim FNotFound As Integer      'used by find function
  289. Dim FAtTop As Integer         'top flag
  290. Dim FEditFlag As Integer      'edit mode
  291. Dim FAddNewFlag As Integer    'add mode
  292. Dim FFldDataChanged As Integer
  293. Dim FFindForm As New fFind    'find form instance
  294. Dim FCurrRec As Integer       'record counter
  295. Dim FNumbRows As Long         'total rows in dynaset
  296. Dim FDynaString As String     'dynaset open string
  297.  
  298. Sub AddButton_Click ()
  299.   On Error GoTo AddErr
  300.  
  301.   'set the mode
  302.   FDS.AddNew
  303.   cStatusBar = "Add record"
  304.   FAddNewFlag = True
  305.   If FDS.RecordCount > 0 Then
  306.     FBM = FDS.Bookmark
  307.   Else
  308.     FBM = ""
  309.   End If
  310.  
  311.   ChangeButtons.Visible = True
  312.   ViewButtons.Visible = False
  313.   NextButton.Enabled = False
  314.   FirstButton.Enabled = False
  315.   LastButton.Enabled = False
  316.   PrevButton.Enabled = False
  317.  
  318.   ClearDataFields
  319.   cFieldData(0).SetFocus
  320.   GoTo AddEnd
  321.  
  322. AddErr:
  323.   ShowError
  324.   Resume AddEnd
  325.  
  326. AddEnd:
  327.  
  328. End Sub
  329.  
  330. Sub CancelButton_Click ()
  331.    On Error Resume Next
  332.  
  333.    ChangeButtons.Visible = False
  334.    ViewButtons.Visible = True
  335.    NextButton.Enabled = True
  336.    FirstButton.Enabled = True
  337.    LastButton.Enabled = True
  338.    PrevButton.Enabled = True
  339.  
  340.    FEditFlag = False
  341.    FAddNewFlag = False
  342.    If FBM <> "" Then FDS.Bookmark = FBM
  343.    DisplayCurrentRecord
  344.  
  345. End Sub
  346.  
  347. Sub cFieldData_Change (Index As Integer)
  348.   'just set the flag if data is changed
  349.   'it gets reset to false when a new record is displayed
  350.   FFldDataChanged = True
  351. End Sub
  352.  
  353. Sub cFieldData_KeyDown (Index As Integer, KeyCode As Integer, Shift As Integer)
  354.   If KeyCode = &H73 Then   'F4
  355.     cFieldName_DblClick Index
  356.  
  357.   ElseIf KeyCode = 34 And cScrollBar.Visible = True Then
  358.     'pagedown with > 10 fields
  359.     cScrollBar = cScrollBar - 3000
  360.  
  361.   ElseIf KeyCode = 33 And cScrollBar.Visible = True Then
  362.     'pageup with > 10 fields
  363.     cScrollBar = cScrollBar + 3000
  364.  
  365.   End If
  366. End Sub
  367.  
  368. Sub cFieldData_KeyPress (Index As Integer, KeyAscii As Integer)
  369.   'only allow return when in edit of add mode
  370.   If FEditFlag = True Or FAddNewFlag = True Then
  371.     If FDS(Index).Type = FT_STRING And Len(cFieldData(Index)) > FDS(Index).Size Then
  372.       Beep
  373.       MsgBox "Field Length Exceeded!", 48
  374.       KeyAscii = 0
  375.       Exit Sub
  376.     End If
  377.     If KeyAscii = 13 Then
  378.       KeyAscii = 0
  379.       SendKeys "{Tab}"
  380.     End If
  381.  
  382.   'throw away the keystrokes if not in add or edit mode
  383.   ElseIf FEditFlag = False And FAddNewFlag = False Then
  384.     KeyAscii = 0
  385.   End If
  386.  
  387. End Sub
  388.  
  389. Sub cFieldData_LostFocus (Index As Integer)
  390.   On Error GoTo FldDataErr
  391.  
  392.   If FFldDataChanged = True Then
  393.     'store the data in the field
  394.     FDS(Index) = cFieldData(Index)
  395.   End If
  396.  
  397.   GoTo FldDataEnd
  398.  
  399. FldDataErr:
  400.   ShowError
  401.   Resume FldDataEnd
  402.  
  403. FldDataEnd:
  404.   'reset for valid or error condition
  405.   FFldDataChanged = False
  406.  
  407. End Sub
  408.  
  409. Sub cFieldName_DblClick (Index As Integer)
  410.   On Error GoTo ZoomErr
  411.  
  412.   If FDS(Index).Type = FT_STRING Or FDS(Index).Type = FT_MEMO Then
  413.      If FDS(Index).FieldSize() < GETCHUNK_CUTOFF Then
  414.        gstZoomData = cFieldData(Index)
  415.      Else
  416.        'add the rest of the field data with getchunk
  417.        MsgBar "Getting Memo Field Data", True
  418.        SetHourglass Me
  419.        gstZoomData = cFieldData(Index) + StripNonAscii(FDS(Index).GetChunk(GETCHUNK_CUTOFF, MAX_MEMO_SIZE))
  420.        ResetMouse Me
  421.        MsgBar "", False
  422.      End If
  423.      fZoom.Caption = Mid(cFieldName(Index), 1, Len(cFieldName(Index)) - 1)
  424.      fZoom.Top = Top + 1200
  425.      fZoom.Left = Left + 250
  426.      If FAddNewFlag Or FEditFlag Then
  427.        fZoom.SaveButton.Visible = True
  428.        fZoom.CloseButton.Visible = True
  429.      Else
  430.        fZoom.CloseZoomButton.Visible = True
  431.      End If
  432.      fZoom.Show MODAL
  433.      If FAddNewFlag Or FEditFlag Then
  434.        If FDS(Index).Type = FT_STRING And Len(gstZoomData) > FDS(Index).Size Then
  435.          Beep
  436.          MsgBox "Field Length Exceeded, Data Truncated!", 48
  437.          cFieldData(Index) = Mid(gstZoomData, 1, FDS(Index).Size)
  438.        Else
  439.          cFieldData(Index) = gstZoomData
  440.        End If
  441.        FDS(Index) = cFieldData(Index)
  442.        FFldDataChanged = False
  443.      End If
  444.   End If
  445.   GoTo ZoomEnd
  446.  
  447. ZoomErr:
  448.   ShowError
  449.   Resume ZoomEnd
  450.  
  451. ZoomEnd:
  452.  
  453. End Sub
  454.  
  455. Sub ClearDataFields ()
  456.   Dim i As Integer
  457.  
  458.   'clear out the fields on the main form
  459.   For i = 0 To FDS.Fields.Count - 1
  460.     cFieldData(i) = ""
  461.   Next
  462. End Sub
  463.  
  464. Sub CloseButton_Click ()
  465.   Unload Me
  466. End Sub
  467.  
  468. Sub cScrollBar_Change ()
  469.   Dim t As Integer
  470.  
  471.   t = cScrollBar
  472.   If (t - 720) Mod 300 = 0 Then
  473.     cFields.Top = t
  474.   Else
  475.     cFields.Top = ((t - 720) \ 300) * 300 + 720
  476.   End If
  477.  
  478. End Sub
  479.  
  480. Sub DelButton_Click ()
  481.   On Error GoTo DelRecErr
  482.  
  483.   If MsgBox("Delete Current Record?", MSGBOX_TYPE) = YES Then
  484.     FDS.Delete
  485.     If gfTransPending Then gfDBChanged = True
  486.     If FDS.EOF = False Then
  487.       FDS.MoveNext
  488.     End If
  489.     FNumbRows = FNumbRows - 1
  490.     DisplayCurrentRecord
  491.   End If
  492.  
  493.   GoTo DelRecEnd
  494.  
  495. DelRecErr:
  496.   ShowError
  497.   Resume DelRecEnd
  498.  
  499. DelRecEnd:
  500.  
  501. End Sub
  502.  
  503. Sub DisplayCurrentRecord ()
  504.    Dim i As Integer
  505.    Dim cst As String    'current status bar
  506.  
  507.    On Error GoTo DCRErr
  508.  
  509.    SetHourglass Me
  510.  
  511.    cst = "Record "
  512.    'check BOF/EOF flag so we know if we
  513.    'are sitting on a valid record
  514.    If FAddNewFlag = True Then
  515.      cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  516.    Else
  517.      If FDS.BOF = True Then
  518.        cst = cst + "(BOF) of " + CStr(FNumbRows)
  519.        ClearDataFields
  520.      ElseIf FDS.EOF = True Then
  521.        cst = cst + "(EOF) of " + CStr(FNumbRows)
  522.        ClearDataFields
  523.      Else
  524.        cst = cst + CStr(FCurrRec) + " of " + CStr(FNumbRows)
  525.        'place the data in the form fields
  526.        For i = 0 To FDS.Fields.Count - 1
  527.          If FDS(i).Type = FT_MEMO Then
  528.            If FDS(i).FieldSize() < GETCHUNK_CUTOFF Then
  529.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  530.            Else
  531.              cFieldData(i) = StripNonAscii(vFieldVal(FDS(i).GetChunk(0, GETCHUNK_CUTOFF)))
  532.            End If
  533.          ElseIf FDS(i).Type = FT_STRING Then
  534.            cFieldData(i) = StripNonAscii(vFieldVal(FDS(i)))
  535.          Else
  536.            cFieldData(i) = vFieldVal(FDS(i))
  537.          End If
  538.        Next
  539.      End If
  540.    End If
  541.    If gfUpdatable = False Then cst = cst + "  [Not Updatable]"
  542.    cStatusBar = cst
  543.    'set the flag
  544.    FFldDataChanged = False
  545.  
  546.    GoTo DCREnd
  547.  
  548. DCRErr:
  549.   ShowError
  550.   Resume DCREnd
  551.  
  552. DCREnd:
  553.    ResetMouse Me
  554.  
  555. End Sub
  556.  
  557. Sub EditButton_Click ()
  558.    On Error GoTo EditErr
  559.  
  560.    FDS.Edit
  561.    cStatusBar = "Edit record"
  562.    FEditFlag = True
  563.    cFieldData(0).SetFocus
  564.    FBM = FDS.Bookmark
  565.  
  566.    ChangeButtons.Visible = True
  567.    ViewButtons.Visible = False
  568.    NextButton.Enabled = False
  569.    FirstButton.Enabled = False
  570.    LastButton.Enabled = False
  571.    PrevButton.Enabled = False
  572.  
  573.    GoTo EditEnd
  574.  
  575. EditErr:
  576.   ShowError
  577.   Resume EditEnd
  578.  
  579. EditEnd:
  580.  
  581. End Sub
  582.  
  583. Sub FilterButton_Click ()
  584.   On Error GoTo FilterErr
  585.  
  586.   Dim bm As String
  587.   Dim ds1 As dynaset, ds2 As dynaset
  588.   Dim FilterStr As String
  589.  
  590.   bm = FDS.Bookmark        'save the bookmark
  591.   Set ds1 = FDS            'save the dynaset
  592.   
  593.   FilterStr = InputBox("Enter Filter Expression:")
  594.   If FilterStr = "" Then Exit Sub
  595.  
  596.   SetHourglass Me
  597.   MsgBar "Setting New Filter", True
  598.   FDS.Filter = FilterStr
  599.   Set ds2 = FDS.CreateDynaset()            'establish the filter
  600.   Set FDS = ds2            'assign back to original dynaset object
  601.  
  602.   'everything must be okay so redisplay form on 1st record
  603.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  604.   FCurrRec = 1
  605.   DisplayCurrentRecord     'display field values
  606.   FAtTop = True
  607.   ResetMouse Me
  608.   MsgBar "", False
  609.   GoTo FilterEnd
  610.  
  611. FilterErr:
  612.   ResetMouse Me
  613.   MsgBar "", False
  614.   ShowError
  615.   Set FDS = ds1            're-assign back to original
  616.   FDS.Bookmark = bm        'go back to original record
  617.   Resume FilterEnd
  618.  
  619. FilterEnd:
  620.  
  621. End Sub
  622.  
  623. Sub FindButton_Click ()
  624.   Dim i As Integer
  625.   Dim bm As String
  626.  
  627.   On Error GoTo FindErr
  628.  
  629.   'load the column names into the find form
  630.   If FFindForm.cFieldList.ListCount = 0 Then
  631.     For i = 0 To FDS.Fields.Count - 1
  632.       FFindForm.cFieldList.AddItem Mid(cFieldName(i), 1, Len(cFieldName(i)) - 1)
  633.     Next
  634.   End If
  635.  
  636. FindStart:
  637.  
  638.   'reset the flags
  639.   gfFindFailed = False
  640.   gfFromTableView = False
  641.   FNotFound = False
  642.  
  643.   MsgBar "Enter Search Parameters", False
  644.   FFindForm.Show MODAL
  645.   MsgBar "Searching for New Record", True
  646.   If gfFindFailed = True Then   'find cancelled
  647.     GoTo AfterWhile
  648.   End If
  649.  
  650.   SetHourglass Me
  651.  
  652.    i = FFindForm.cFieldList.ListIndex
  653.    'search for the record
  654.    bm = FDS.Bookmark
  655.    If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  656.      FDS.FindFirst FDS(i).Name + " " + gstFindOp + " '" + gstFindExpr + "'"
  657.    Else
  658.      FDS.FindFirst FDS(i).Name + gstFindOp + gstFindExpr
  659.    End If
  660.    FNotFound = FDS.NoMatch
  661.  
  662. AfterWhile:
  663.  
  664.    ResetMouse Me
  665.  
  666.    If gfFindFailed = True Then   'go back to top
  667.      FDS.Bookmark = bm
  668.    ElseIf FNotFound Then
  669.      Beep
  670.      MsgBox "Record Not Found", 48
  671.      FDS.Bookmark = bm
  672.      GoTo FindStart
  673.    Else
  674.      bm = FDS.Bookmark
  675.      FDS.MoveFirst
  676.      FCurrRec = 1
  677.      While FDS.Bookmark <> bm
  678.        FCurrRec = FCurrRec + 1
  679.        FDS.MoveNext
  680.      Wend
  681.    End If
  682.  
  683.    DisplayCurrentRecord
  684.  
  685.    GoTo FindEnd
  686.  
  687. FindErr:
  688.    ResetMouse Me
  689.    If Err <> EOF_ERR Then
  690.      ShowError
  691.      Resume FindEnd
  692.    Else
  693.      FNotFound = True
  694.      Resume Next
  695.    End If
  696.  
  697. FindEnd:
  698.    MsgBar "", False
  699.  
  700. End Sub
  701.  
  702. Sub FirstButton_Click ()
  703.    Dim ds As String
  704.    On Error GoTo GoFirstError
  705.  
  706.    FDS.MoveFirst
  707.    FCurrRec = 1
  708.    DisplayCurrentRecord
  709.    FAtTop = True
  710.  
  711.    GoTo GoFirstEnd
  712.  
  713. GoFirstError:
  714.    ShowError
  715.    Resume GoFirstEnd
  716.  
  717. GoFirstEnd:
  718.    ResetMouse Me
  719.    MsgBar "", False
  720.  
  721. End Sub
  722.  
  723. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  724.   If FEditFlag = True Or FAddNewFlag = True Then Exit Sub
  725.   
  726.   Select Case KeyCode
  727.     Case 35                'end
  728.       Call LastButton_Click
  729.     Case 36                'home
  730.       Call FirstButton_Click
  731.     Case 38                'up arrow
  732.       If Shift = 2 Then
  733.         Call FirstButton_Click
  734.       Else
  735.         Call PrevButton_Click
  736.       End If
  737.     Case 40                'down arrow
  738.       If Shift = 2 Then
  739.         Call LastButton_Click
  740.       Else
  741.         Call NextButton_Click
  742.       End If
  743.     Case 114                'F3
  744.       Call FindButton_Click
  745.  
  746.   End Select
  747.  
  748. End Sub
  749.  
  750. Sub Form_Load ()
  751.    Dim t As TableDef       'local table structure
  752.    Dim sp As Integer       'starting point of table name
  753.    Dim ep As Integer       'ending point of table name
  754.    Dim ds As String        'temp dynaset name string
  755.    Dim wh As String        'where clause
  756.  
  757.    Dim ft As Integer
  758.    Dim i As Integer, j As Integer
  759.    Dim fn As String        'field name
  760.    Dim l As Long
  761.  
  762.    Dim Start1, Finish1, Start2, Finish2
  763.  
  764.    On Error GoTo DynasetErr
  765.  
  766.    SetHourglass Me
  767.    MsgBar "Opening Dynaset", True
  768.  
  769.    'disable match case checkbox on find form
  770.    'because it isn't implemented on this form
  771.    FFindForm.cMatchCase.Enabled = False
  772.  
  773.    'assign the temp string with the select statement
  774.    'if it is not empty, otherwise, use the table list name
  775.    If gfFromSQL = True Then
  776.      If gstDynaString = "" Then
  777.        ds = fSQL.cSQLStatement
  778.      Else
  779.        ds = gstDynaString
  780.      End If
  781.    ElseIf gstTableDynaFilter <> "" Then
  782.      ds = gstTableDynaFilter
  783.    Else
  784.      ds = fTables.cTableList
  785.    End If
  786.  
  787.    'attemp to open the dynaset
  788.    Start1 = Timer
  789.  
  790.    If gfFromSQL = True And fSQL.cPassThru = 1 Then
  791.      Set FDS = gCurrentDB.CreateDynaset(ds, VBDA_SQLPASSTHROUGH)
  792.    Else
  793.      Set FDS = gCurrentDB.CreateDynaset(ds)
  794.    End If
  795.    Finish1 = Timer
  796.  
  797.    Start2 = Timer
  798.    'parse off table name to store in global gstTblName
  799.    wh = ""
  800.    sp = InStr(1, UCase(ds), "FROM")
  801.    If sp > 0 Then
  802.      'must be a "select from" statement
  803.      sp = sp + 5
  804.      For ep = sp To Len(ds)
  805.        'search for a space or the end of ds
  806.        If Mid$(ds, ep, 1) = " " Then
  807.          'get where clause if there is one
  808.          wh = Mid$(ds, sp, Len(ds) - sp + 1)
  809.          Exit For
  810.        End If
  811.      Next
  812.      FTblName = UCase(Mid$(ds, sp, ep - sp))
  813.      If wh = "" Then wh = FTblName
  814.    Else
  815.      'must be a table name only
  816.      FTblName = UCase(ds)
  817.      wh = FTblName
  818.    End If
  819.  
  820.    FDynaString = wh
  821.  
  822.    'show the first record
  823.    FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  824.  
  825.    'load the controls on the dynaset form
  826.    cFieldName(0).Visible = True
  827.    cFieldData(0).Visible = True
  828.    ft = FDS(0).Type
  829.    cFieldData(0).Width = GetFieldWidth(ft)
  830.    cFieldData(0).TabIndex = 0
  831.    For i = 1 To FDS.Fields.Count - 1
  832.      cFields.Height = cFields.Height + 300
  833.      Load cFieldName(i)
  834.      cFieldName(i).Top = cFieldName(i - 1).Top + 300
  835.      cFieldName(i).Visible = True
  836.      Load cFieldData(i)
  837.      cFieldData(i).Top = cFieldData(i - 1).Top + 300
  838.      cFieldData(i).Visible = True
  839.      ft = FDS.Fields(i).Type
  840.      cFieldData(i).Width = GetFieldWidth(ft)
  841.      cFieldData(i).TabIndex = i
  842.    Next
  843.  
  844.    'resize main window
  845.    If i <= 10 Then
  846.      Height = ((i + 1) * 300) + 1400
  847.    Else
  848.      Height = 4368
  849.      Width = Width + 260
  850.      cScrollBar.Visible = True
  851.      cScrollBar.Min = 720
  852.      cScrollBar.Max = 720 - (i * 300) + 3000
  853.    End If
  854.  
  855.    'display the field names
  856.    For i = 0 To FDS.Fields.Count - 1
  857.      cFieldName(i) = UCase(FDS(i).Name) + ":"
  858.    Next
  859.  
  860.    FCurrRec = 1
  861.    DisplayCurrentRecord      'display field values
  862.    FAtTop = True
  863.  
  864.    If gstTableDynaFilter <> "" Then
  865.      Caption = "Filtered Dynaset: " + FTblName
  866.    Else
  867.      Caption = "Dynaset: " + FTblName
  868.    End If
  869.    Width = 5805
  870.    Left = 1000
  871.    Top = 1000
  872.    
  873.    Finish2 = Timer
  874.    If VDMDI.PrefShowPerf.Checked Then
  875.      Me.Show
  876.      MsgBox CStr(FNumbRows) + " rows found in " + CStr(Finish1 - Start1) + " seconds!" + Chr(13) + Chr(10) + CStr(Finish2 - Start2) + " seconds to Get Record Count!", 48
  877.    End If
  878.  
  879.    GoTo OkayEnd
  880.  
  881. DynasetErr:
  882.    ShowError
  883.    ResetMouse Me
  884.    Unload Me
  885.    MsgBar "", False
  886.    Exit Sub
  887.    Resume OkayEnd
  888.  
  889. OkayEnd:
  890.    ResetMouse Me
  891.    MsgBar "", False
  892.  
  893. End Sub
  894.  
  895. Sub Form_Paint ()
  896.   Outlines Me
  897. End Sub
  898.  
  899. Sub Form_Resize ()
  900.   On Error Resume Next
  901.  
  902.   Dim h As Integer, i As Integer
  903.   Dim totw As Integer
  904.  
  905.   If WindowState <> 1 Then   'not minimized
  906.     MsgBar "Resizing Form", True
  907.     'make sure the form is lined up on a field
  908.     h = Height
  909.     If (h - 1420) Mod 300 <> 0 Then
  910.       Height = ((h - 1420) \ 300) * 300 + 1420
  911.     End If
  912.     'resize the status bar
  913.     StatBox.Top = Height - 650
  914.     'resize the scrollbar
  915.     cScrollBar.Height = StatBox.Top - (ViewButtons.Top - FieldHeader.Height) - 960
  916.     cScrollBar.Left = Width - 360
  917.     If FDS.Fields.Count > 10 Then
  918.       cFields.Width = Width - 260
  919.       totw = cScrollBar.Left - 20
  920.     Else
  921.       cFields.Width = Width - 20
  922.       totw = Width - 50
  923.     End If
  924.     FieldHeader.Width = Width - 20
  925.     'widen the fields if possible
  926.     For i = 0 To FDS.Fields.Count - 1
  927.       cFieldName(i).Width = .3 * totw
  928.       cFieldData(i).Left = cFieldName(i).Width + 20
  929.       If FDS(i).Type = FT_STRING Or FDS(i).Type = FT_MEMO Then
  930.         cFieldData(i).Width = .7 * totw - 250
  931.       End If
  932.     Next
  933.     FieldValueLabel.Left = cFieldData(0).Left
  934.     cStatusBar.Width = Width - 1600
  935.     NextButton.Left = cStatusBar.Width + 745
  936.     LastButton.Left = NextButton.Left + 370
  937.   End If
  938.   MsgBar "", False
  939. End Sub
  940.  
  941. Sub Form_Unload (Cancel As Integer)
  942.   On Error Resume Next
  943.  
  944.   Unload FFindForm   'get rid of attached find form
  945.   FDS.Close          'close the form dynaset
  946.   MsgBar "", False
  947. End Sub
  948.  
  949. Sub LastButton_Click ()
  950.    On Error GoTo GoLastError
  951.  
  952.    FDS.MoveLast
  953.    'show the current record
  954.    FCurrRec = FNumbRows
  955.    DisplayCurrentRecord
  956.  
  957.    GoTo GoLastEnd
  958.  
  959. GoLastError:
  960.    ShowError
  961.    Resume GoLastEnd
  962.  
  963. GoLastEnd:
  964.  
  965. End Sub
  966.  
  967. Sub NextButton_Click ()
  968.    On Error GoTo GoNextError
  969.  
  970.    FDS.MoveNext
  971.    'show the current record
  972.    FCurrRec = FCurrRec + 1   'bump the record counter
  973.    DisplayCurrentRecord
  974.    FAtTop = False
  975.  
  976.    GoTo GoNextEnd
  977.  
  978. GoNextError:
  979.    ShowError
  980.    Resume GoNextEnd
  981.  
  982. GoNextEnd:
  983.  
  984. End Sub
  985.  
  986. Sub PrevButton_Click ()
  987.    On Error GoTo GoPrevError
  988.  
  989.    FDS.MovePrevious
  990.    'show the current record
  991.    FCurrRec = FCurrRec - 1   'bump the record counter back
  992.    DisplayCurrentRecord
  993.    FAtTop = False
  994.  
  995.    GoTo GoPrevEnd
  996.  
  997. GoPrevError:
  998.    ShowError
  999.    Resume GoPrevEnd
  1000.  
  1001. GoPrevEnd:
  1002.  
  1003. End Sub
  1004.  
  1005. Sub PropButton_Click ()
  1006.    Dim f As New fDataBox
  1007.  
  1008.    On Error GoTo DynPropErr
  1009.  
  1010.    Set gCurrentDS = FDS
  1011.    f.Caption = "Dynaset Properties"
  1012.    f.Tag = "DS"
  1013.  
  1014.    f.cData.AddItem "Name = " + FDS.Name
  1015.    f.cData.AddItem "BOF Flag = " + stTrueFalse((FDS.BOF))
  1016.    f.cData.AddItem "BookMark = " + FDS.Bookmark
  1017.    f.cData.AddItem "BookMarkable Flag = " + stTrueFalse((FDS.Bookmarkable))
  1018.    f.cData.AddItem "EOF Flag = " + stTrueFalse((FDS.EOF))
  1019.    f.cData.AddItem "Filter = " + FDS.Filter
  1020.    f.cData.AddItem "Last Modified = " + FDS.LastModified
  1021.    f.cData.AddItem "Lock Edits Flag = " + stTrueFalse((FDS.LockEdits))
  1022.    f.cData.AddItem "No Match Flag = " + stTrueFalse((FDS.NoMatch))
  1023.    f.cData.AddItem "Sort = " + FDS.Sort
  1024.    f.cData.AddItem "Transactions Flag = " + stTrueFalse((FDS.Transactions))
  1025.    f.cData.AddItem "RecordCount = " & FDS.RecordCount
  1026.    f.cData.AddItem "Updatable Flag = " + stTrueFalse((FDS.Updatable))
  1027.  
  1028.    f.Show MODAL
  1029.  
  1030.   GoTo DynPropEnd
  1031.  
  1032. DynPropErr:
  1033.   f.cData.AddItem Error$
  1034.   Resume Next
  1035.  
  1036. DynPropEnd:
  1037.  
  1038. End Sub
  1039.  
  1040. Sub SortButton_Click ()
  1041.   On Error GoTo SortErr
  1042.  
  1043.   Dim bm As String
  1044.   Dim ds1 As dynaset, ds2 As dynaset
  1045.   Dim SortStr As String
  1046.  
  1047.   bm = FDS.Bookmark        'save the bookmark
  1048.   Set ds1 = FDS            'save the dynaset
  1049.   
  1050.   SortStr = InputBox("Enter Sort Column:")
  1051.   If SortStr = "" Then Exit Sub
  1052.  
  1053.   SetHourglass Me
  1054.   MsgBar "Setting New Sort Order", True
  1055.   FDS.Sort = SortStr
  1056.   Set ds2 = FDS.CreateDynaset()            'establish the Sort
  1057.   Set FDS = ds2            'assign back to original dynaset object
  1058.  
  1059.   'everything must be okay so redisplay form on 1st record
  1060.   FNumbRows = GetNumbRecs(FDS)          'query numb of recs
  1061.   FCurrRec = 1
  1062.   DisplayCurrentRecord     'display field values
  1063.   FAtTop = True
  1064.   ResetMouse Me
  1065.   MsgBar "", False
  1066.   GoTo SortEnd
  1067.  
  1068. SortErr:
  1069.   ResetMouse Me
  1070.   MsgBar "", False
  1071.   ShowError
  1072.   Set FDS = ds1            're-assign back to original
  1073.   FDS.Bookmark = bm        'go back to original record
  1074.   Resume SortEnd
  1075.  
  1076. SortEnd:
  1077.  
  1078. End Sub
  1079.  
  1080. Sub UpdateButton_Click ()
  1081.   On Error GoTo UpdateErr
  1082.  
  1083.   FDS.Update
  1084.   If gfTransPending Then gfDBChanged = True
  1085.  
  1086.   If FAddNewFlag = True Then
  1087.     FNumbRows = FNumbRows + 1
  1088.     FCurrRec = FNumbRows
  1089.     FDS.MoveLast             'move to the new record
  1090.   End If
  1091.  
  1092.   ChangeButtons.Visible = False
  1093.   ViewButtons.Visible = True
  1094.   NextButton.Enabled = True
  1095.   FirstButton.Enabled = True
  1096.   LastButton.Enabled = True
  1097.   PrevButton.Enabled = True
  1098.   FEditFlag = False
  1099.   FAddNewFlag = False
  1100.   DisplayCurrentRecord
  1101.  
  1102.   GoTo UpdateEnd
  1103.  
  1104. UpdateErr:
  1105.   ShowError
  1106.   Resume UpdateEnd
  1107.  
  1108. UpdateEnd:
  1109.  
  1110. End Sub
  1111.  
  1112.