home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / query / mquery / mdynast.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-05-24  |  25.6 KB  |  875 lines

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