home *** CD-ROM | disk | FTP | other *** search
/ Master 95 #1 / MASTER95_1.iso / microsof / vbasic4 / vb4-6.cab / dynasnap.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-26  |  32.3 KB  |  948 lines

  1. VERSION 4.00
  2. Begin VB.Form frmDynaSnap 
  3.    ClientHeight    =   3750
  4.    ClientLeft      =   1845
  5.    ClientTop       =   2130
  6.    ClientWidth     =   5460
  7.    Height          =   4155
  8.    HelpContextID   =   2016125
  9.    Icon            =   "DYNASNAP.frx":0000
  10.    KeyPreview      =   -1  'True
  11.    Left            =   1785
  12.    LinkTopic       =   "Form1"
  13.    LockControls    =   -1  'True
  14.    MDIChild        =   -1  'True
  15.    ScaleHeight     =   3733.906
  16.    ScaleMode       =   0  'User
  17.    ScaleWidth      =   5479.612
  18.    Tag             =   "Recordset"
  19.    Top             =   1785
  20.    Width           =   5580
  21.    Begin VB.PictureBox picViewButtons 
  22.       Align           =   1  'Align Top
  23.       Appearance      =   0  'Flat
  24.       BorderStyle     =   0  'None
  25.       ForeColor       =   &H80000008&
  26.       Height          =   855
  27.       Left            =   0
  28.       ScaleHeight     =   855
  29.       ScaleMode       =   0  'User
  30.       ScaleWidth      =   5463.258
  31.       TabIndex        =   14
  32.       TabStop         =   0   'False
  33.       Top             =   0
  34.       Width           =   5460
  35.       Begin VB.CommandButton cmdMove 
  36.          Caption         =   "&Move"
  37.          Height          =   345
  38.          Left            =   1080
  39.          TabIndex        =   8
  40.          TabStop         =   0   'False
  41.          Top             =   360
  42.          Width           =   1095
  43.       End
  44.       Begin VB.CommandButton cmdSort 
  45.          Caption         =   "&Sort"
  46.          Height          =   345
  47.          Left            =   0
  48.          TabIndex        =   6
  49.          Top             =   360
  50.          Width           =   1095
  51.       End
  52.       Begin VB.CommandButton cmdFilter 
  53.          Caption         =   "F&ilter"
  54.          Height          =   345
  55.          Left            =   4320
  56.          TabIndex        =   5
  57.          Top             =   20
  58.          Width           =   1095
  59.       End
  60.       Begin VB.CommandButton cmdClose 
  61.          Caption         =   "&Close"
  62.          Height          =   345
  63.          Left            =   3240
  64.          TabIndex        =   9
  65.          TabStop         =   0   'False
  66.          Top             =   360
  67.          Width           =   1095
  68.       End
  69.       Begin VB.CommandButton cmdProperties 
  70.          Caption         =   "&Prop"
  71.          Height          =   345
  72.          Left            =   2160
  73.          TabIndex        =   7
  74.          Top             =   360
  75.          Width           =   1095
  76.       End
  77.       Begin VB.CommandButton cmdDelete 
  78.          Caption         =   "&Delete"
  79.          Height          =   345
  80.          Left            =   2160
  81.          TabIndex        =   3
  82.          Top             =   20
  83.          Width           =   1095
  84.       End
  85.       Begin VB.CommandButton cmdEdit 
  86.          Caption         =   "&Edit"
  87.          Height          =   345
  88.          Left            =   1080
  89.          TabIndex        =   2
  90.          Top             =   20
  91.          Width           =   1095
  92.       End
  93.       Begin VB.CommandButton cmdAdd 
  94.          Caption         =   "&Add"
  95.          Height          =   345
  96.          Left            =   0
  97.          TabIndex        =   1
  98.          Top             =   20
  99.          Width           =   1095
  100.       End
  101.       Begin VB.CommandButton cmdFind 
  102.          Caption         =   "&Find"
  103.          Height          =   345
  104.          Left            =   3240
  105.          TabIndex        =   4
  106.          Top             =   20
  107.          Width           =   1095
  108.       End
  109.    End
  110.    Begin VB.PictureBox picChangeButtons 
  111.       Appearance      =   0  'Flat
  112.       BorderStyle     =   0  'None
  113.       ForeColor       =   &H80000008&
  114.       Height          =   855
  115.       Left            =   0
  116.       ScaleHeight     =   919.528
  117.       ScaleMode       =   0  'User
  118.       ScaleWidth      =   5719.056
  119.       TabIndex        =   15
  120.       TabStop         =   0   'False
  121.       Top             =   0
  122.       Visible         =   0   'False
  123.       Width           =   5655
  124.       Begin VB.CommandButton cmdUpdate 
  125.          Caption         =   "&Update"
  126.          Height          =   372
  127.          Left            =   960
  128.          TabIndex        =   12
  129.          Top             =   48
  130.          Width           =   1212
  131.       End
  132.       Begin VB.CommandButton cmdCancel 
  133.          Caption         =   "&Cancel"
  134.          Height          =   372
  135.          Left            =   2640
  136.          TabIndex        =   13
  137.          Top             =   48
  138.          Width           =   1212
  139.       End
  140.    End
  141.    Begin VB.PictureBox picFldHdr 
  142.       Appearance      =   0  'Flat
  143.       BorderStyle     =   0  'None
  144.       ForeColor       =   &H80000008&
  145.       Height          =   240
  146.       Left            =   0
  147.       ScaleHeight     =   240
  148.       ScaleMode       =   0  'User
  149.       ScaleWidth      =   14948.92
  150.       TabIndex        =   19
  151.       TabStop         =   0   'False
  152.       Top             =   840
  153.       Width           =   14946
  154.       Begin VB.Label lblFieldValue 
  155.          Caption         =   " Value (F4=Zoom)"
  156.          Height          =   255
  157.          Left            =   1680
  158.          TabIndex        =   21
  159.          Top             =   0
  160.          Width           =   2295
  161.       End
  162.       Begin VB.Label lblFieldHdr 
  163.          Caption         =   "Field Name:"
  164.          Height          =   252
  165.          Left            =   120
  166.          TabIndex        =   20
  167.          Top             =   0
  168.          Width           =   1212
  169.       End
  170.    End
  171.    Begin VB.PictureBox picMoveButtons 
  172.       Align           =   2  'Align Bottom
  173.       Appearance      =   0  'Flat
  174.       BorderStyle     =   0  'None
  175.       ForeColor       =   &H80000008&
  176.       Height          =   285
  177.       Left            =   0
  178.       ScaleHeight     =   298.153
  179.       ScaleMode       =   0  'User
  180.       ScaleWidth      =   5469.835
  181.       TabIndex        =   18
  182.       TabStop         =   0   'False
  183.       Top             =   3465
  184.       Width           =   5460
  185.       Begin VB.HScrollBar hsclCurrRow 
  186.          Height          =   255
  187.          Left            =   0
  188.          Max             =   100
  189.          TabIndex        =   10
  190.          Top             =   29
  191.          Width           =   2895
  192.       End
  193.       Begin VB.Label lblStatus 
  194.          Height          =   255
  195.          Left            =   3000
  196.          TabIndex        =   22
  197.          Top             =   38
  198.          Width           =   1695
  199.       End
  200.    End
  201.    Begin VB.VScrollBar vsbScrollBar 
  202.       Height          =   2250
  203.       LargeChange     =   3000
  204.       Left            =   5040
  205.       SmallChange     =   300
  206.       TabIndex        =   11
  207.       Top             =   1080
  208.       Visible         =   0   'False
  209.       Width           =   255
  210.    End
  211.    Begin VB.PictureBox picFields 
  212.       Appearance      =   0  'Flat
  213.       BorderStyle     =   0  'None
  214.       ForeColor       =   &H80000008&
  215.       Height          =   375
  216.       Left            =   120
  217.       ScaleHeight     =   372
  218.       ScaleMode       =   0  'User
  219.       ScaleWidth      =   4812
  220.       TabIndex        =   16
  221.       TabStop         =   0   'False
  222.       Top             =   1080
  223.       Width           =   4815
  224.       Begin VB.TextBox txtFieldData 
  225.          BackColor       =   &H00FFFFFF&
  226.          DataSource      =   "Data1"
  227.          ForeColor       =   &H00000000&
  228.          Height          =   288
  229.          Index           =   0
  230.          Left            =   1560
  231.          TabIndex        =   0
  232.          Top             =   0
  233.          Visible         =   0   'False
  234.          Width           =   3252
  235.       End
  236.       Begin VB.Label lblFieldName 
  237.          ForeColor       =   &H00000000&
  238.          Height          =   252
  239.          Index           =   0
  240.          Left            =   0
  241.          TabIndex        =   17
  242.          Top             =   60
  243.          Visible         =   0   'False
  244.          Width           =   1572
  245.       End
  246.    End
  247. Attribute VB_Name = "frmDynaSnap"
  248. Attribute VB_Creatable = False
  249. Attribute VB_Exposed = False
  250. Option Explicit
  251. 'form variables
  252. Dim mrecFormRecordset As Recordset  'current form's recordset
  253. Dim msTableName As String      'form recordset table name
  254. Dim msBookMark As String       'form bookmark
  255. Dim mbNotFound As Integer      'used by find function
  256. Dim mbEditFlag As Integer      'edit mode
  257. Dim mbAddNewFlag As Integer    'add mode
  258. Dim mbDataChanged As Integer   'field data dirty flag
  259. Dim mfrmFind As New frmFindForm      'find form instance
  260. Dim mlNumRows As Long          'total rows in recordset
  261. Private Sub cmdAdd_Click()
  262.   On Error GoTo AddErr
  263.   'set the mode
  264.   mrecFormRecordset.AddNew
  265.   lblStatus.Caption = "Add record"
  266.   mbAddNewFlag = True
  267.   If mrecFormRecordset.RecordCount > 0 Then
  268.     msBookMark = mrecFormRecordset.Bookmark
  269.   Else
  270.     msBookMark = gsNULL_STR
  271.   End If
  272.   picChangeButtons.Visible = True
  273.   picViewButtons.Visible = False
  274.   hsclCurrRow.Enabled = False
  275.   ClearDataFields Me, mrecFormRecordset.Fields.Count
  276.   txtFieldData(0).SetFocus
  277.   mbDataChanged = False
  278.   Exit Sub
  279. AddErr:
  280.   ShowError
  281.   Exit Sub
  282. End Sub
  283. Private Sub cmdCancel_Click()
  284.    On Error Resume Next
  285.    picChangeButtons.Visible = False
  286.    picViewButtons.Visible = True
  287.    hsclCurrRow.Enabled = True
  288.    mbEditFlag = False
  289.    mbAddNewFlag = False
  290.    mrecFormRecordset.CancelUpdate
  291.    DBEngine.Idle dbFreeLocks
  292.    DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  293.    mbDataChanged = False
  294. End Sub
  295. Private Sub cmdMove_Click()
  296.   On Error GoTo MVErr
  297.   Dim sBookMark As String
  298.   Dim lRows As Long
  299.   lRows = CLng(InputBox("Enter number of Rows to Move:" & gsNewLine & "(Use negative value to move backwards)"))
  300.   If lRows = 0 Then Exit Sub
  301.   mrecFormRecordset.Move lRows
  302.   sBookMark = mrecFormRecordset.Bookmark  'save the new position
  303.   'now we need to reposition the scrollbar to reflect the move
  304.   If mlNumRows > 32767 Then
  305.     hsclCurrRow.VALUE = (mrecFormRecordset.PercentPosition * 32767) / 100 + 1
  306.   ElseIf mlNumRows > 99 Then
  307.     hsclCurrRow.VALUE = (mrecFormRecordset.PercentPosition * mlNumRows) / 100 + 1
  308.   Else
  309.     hsclCurrRow.VALUE = mrecFormRecordset.PercentPosition
  310.   End If
  311.   mrecFormRecordset.Bookmark = sBookMark
  312.   Exit Sub
  313. MVErr:
  314.   ShowError
  315.   Exit Sub
  316. End Sub
  317. Private Sub hsclCurrRow_Change()
  318.   On Error GoTo SCRErr
  319.   Static nPrevVal As Integer
  320.   'based on number of rows, there is different logic needed
  321.   'to set the current position in the recordset
  322.   If mlNumRows > 0 Then
  323.     If mlNumRows > 32767 Then
  324.       'if there are > 32767 we need to use the move methods because
  325.       'the scrollbar is limited to 32767 so if we didn't apply this
  326.       'logic, it would be impossible to get to every record on a
  327.       'small change of the scrollbar
  328.       If hsclCurrRow.VALUE - nPrevVal = 1 Then
  329.         mrecFormRecordset.MoveNext
  330.       ElseIf hsclCurrRow.VALUE - nPrevVal = -1 Then
  331.         mrecFormRecordset.MovePrevious
  332.       Else
  333.         mrecFormRecordset.PercentPosition = (hsclCurrRow.VALUE / 32767) * 100 + 0.005
  334.       End If
  335.       nPrevVal = hsclCurrRow.VALUE
  336.     ElseIf mlNumRows > 99 Then
  337.       'need to calculate the position when there are > 99 recs
  338.       mrecFormRecordset.PercentPosition = (hsclCurrRow.VALUE / mlNumRows) * 100 + 0.005
  339.     Else
  340.       mrecFormRecordset.PercentPosition = hsclCurrRow.VALUE
  341.     End If
  342.   End If
  343.   DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  344.   mbDataChanged = False
  345.   Screen.MousePointer = vbDefault
  346.   MsgBar gsNULL_STR, False
  347.   Exit Sub
  348. SCRErr:
  349.   ShowError
  350.   Exit Sub
  351. End Sub
  352. Private Sub txtFieldData_Change(Index As Integer)
  353.   'just set the flag if data is changed
  354.   'it gets reset to false when a new record is displayed
  355.   mbDataChanged = True
  356. End Sub
  357. Private Sub txtFieldData_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  358.   If KeyCode = &H73 Then   'F4
  359.     lblFieldName_DblClick Index
  360.   ElseIf KeyCode = 34 And vsbScrollBar.Visible = True Then
  361.     'pagedown with > 10 fields
  362.     vsbScrollBar.VALUE = vsbScrollBar.VALUE - 3000
  363.   ElseIf KeyCode = 33 And vsbScrollBar.Visible = True Then
  364.     'pageup with > 10 fields
  365.     vsbScrollBar.VALUE = vsbScrollBar.VALUE + 3000
  366.   End If
  367. End Sub
  368. Private Sub txtFieldData_KeyPress(Index As Integer, KeyAscii As Integer)
  369.   'only allow return when in edit of add mode
  370.   If mbEditFlag = True Or mbAddNewFlag = True Then
  371.     If KeyAscii = 13 Then
  372.       KeyAscii = 0
  373.       SendKeys "{Tab}"
  374.     End If
  375.   'throw away the keystrokes if not in add or edit mode
  376.   ElseIf mbEditFlag = False And mbAddNewFlag = False Then
  377.     KeyAscii = 0
  378.   End If
  379. End Sub
  380. Private Sub txtFieldData_LostFocus(Index As Integer)
  381.   On Error GoTo FldDataErr
  382.   If mbDataChanged = True Then
  383.     'store the data in the field
  384.     mrecFormRecordset(Index) = txtFieldData(Index)
  385.   End If
  386.   'reset for valid or error condition
  387.   mbDataChanged = False
  388.   Exit Sub
  389. FldDataErr:
  390.   'reset for valid or error condition
  391.   mbDataChanged = False
  392.   ShowError
  393.   Exit Sub
  394. End Sub
  395. Private Sub lblFieldName_DblClick(Index As Integer)
  396.   On Error GoTo ZoomErr
  397.   If mrecFormRecordset(Index).Type = dbText Or mrecFormRecordset(Index).Type = dbMemo Then
  398.      If mrecFormRecordset(Index).Type = dbText Then
  399.        gsZoomData = txtFieldData(Index).TEXT
  400.      ElseIf mrecFormRecordset(Index).FieldSize() < gnGETCHUNK_CUTOFF Then
  401.        gsZoomData = txtFieldData(Index).TEXT
  402.      Else
  403.        'add the rest of the field data with getchunk
  404.        MsgBar "Getting Memo Field Data", True
  405.        SetHourglass
  406.        gsZoomData = txtFieldData(Index).TEXT & _
  407.          StripNonAscii(mrecFormRecordset(Index).GetChunk(gnGETCHUNK_CUTOFF, gnMAX_MEMO_SIZE))
  408.        Screen.MousePointer = vbDefault
  409.        MsgBar gsNULL_STR, False
  410.      End If
  411.      frmZoom.Caption = Mid(lblFieldName(Index).Caption, 1, Len(lblFieldName(Index).Caption) - 1)
  412.      If mbAddNewFlag Or mbEditFlag Then
  413.        frmZoom.cmdSave.Visible = True
  414.        frmZoom.cmdCloseNoSave.Visible = True
  415.      Else
  416.        frmZoom.cmdClose.Visible = True
  417.      End If
  418.      If mrecFormRecordset(Index).Type = dbText Then
  419.        frmZoom.txtZoomData.TEXT = gsZoomData
  420.        frmZoom.Height = 1125
  421.      Else
  422.        frmZoom.txtMemo.TEXT = gsZoomData
  423.        frmZoom.txtMemo.Visible = True
  424.        frmZoom.txtZoomData.Visible = False
  425.        frmZoom.Height = 2205
  426.      End If
  427.      frmZoom.Show vbModal
  428.      If (mbAddNewFlag Or mbEditFlag) And gsZoomData <> "__CANCELLED__" Then
  429.        If mrecFormRecordset(Index).Type = dbText And Len(gsZoomData) > mrecFormRecordset(Index).Size Then
  430.          Beep
  431.          MsgBox "Field Length Exceeded, Data Truncated!", 48
  432.          txtFieldData(Index).TEXT = Mid(gsZoomData, 1, mrecFormRecordset(Index).Size)
  433.        Else
  434.          txtFieldData(Index).TEXT = gsZoomData
  435.        End If
  436.        mrecFormRecordset(Index) = txtFieldData(Index).TEXT
  437.        mbDataChanged = False
  438.      End If
  439.   End If
  440.   Exit Sub
  441. ZoomErr:
  442.   ShowError
  443.   Exit Sub
  444. End Sub
  445. Private Sub cmdClose_Click()
  446.   DBEngine.Idle dbFreeLocks
  447.   Unload Me
  448. End Sub
  449. Sub txtFieldData_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, Y As Single)
  450.   If Button <> 2 Then Exit Sub
  451.   ShowProperties "Field", mrecFormRecordset.Fields(Index)
  452. End Sub
  453. Private Sub vsbScrollBar_Change()
  454.   Dim nTop As Integer
  455.   nTop = vsbScrollBar.VALUE
  456.   If (nTop - 1080) Mod gnCTLARRAYHEIGHT = 0 Then
  457.     picFields.TOP = nTop
  458.   Else
  459.     picFields.TOP = ((nTop - 1080) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + 1080
  460.   End If
  461. End Sub
  462. Private Sub cmdDelete_Click()
  463.   On Error GoTo DelRecErr
  464.   If MsgBox("Delete Current Record?", gnMSGBOX_TYPE) = gnMSGBOX_YES Then
  465.     mrecFormRecordset.DELETE
  466.     If gbTransPending Then gbDBChanged = True
  467.     If mrecFormRecordset.EOF = False Then
  468.       mrecFormRecordset.MoveNext
  469.     End If
  470.     mlNumRows = mlNumRows - 1
  471.     SetScrollBar
  472.     DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  473.     mbDataChanged = False
  474.   End If
  475.   Exit Sub
  476. DelRecErr:
  477.   ShowError
  478.   Exit Sub
  479. End Sub
  480. Private Sub cmdEdit_Click()
  481.    On Error GoTo EditErr
  482.   Dim nDelay As Long
  483.   Dim nRetryCnt As Integer
  484.   SetHourglass
  485. RetryEdit:
  486.    mrecFormRecordset.Edit
  487.    lblStatus.Caption = "Edit record"
  488.    mbEditFlag = True
  489.    txtFieldData(0).SetFocus
  490.    msBookMark = mrecFormRecordset.Bookmark
  491.    picChangeButtons.Visible = True
  492.    picViewButtons.Visible = False
  493.    hsclCurrRow.Enabled = False
  494.    Screen.MousePointer = vbDefault
  495.    Exit Sub
  496. EditErr:
  497.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  498.     nRetryCnt = nRetryCnt + 1
  499.     DBEngine.Idle dbFreeLocks
  500.     'Wait gnMUDelay seconds
  501.     nDelay = Timer
  502.     While Timer - nDelay < gnMUDelay
  503.       'do nothing
  504.     Wend
  505.     Resume RetryEdit
  506.   Else
  507.     ShowError
  508.     Exit Sub
  509.   End If
  510. End Sub
  511. Private Sub cmdFilter_Click()
  512.   On Error GoTo FilterErr
  513.   Dim sBookMark As String
  514.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  515.   Dim sFilterStr As String
  516.   sBookMark = mrecFormRecordset.Bookmark        'save the bookmark
  517.   Set recRecordset1 = mrecFormRecordset            'save the recordset
  518.   sFilterStr = InputBox("Enter Filter Expression:")
  519.   If Len(sFilterStr) = 0 Then Exit Sub
  520.   SetHourglass
  521.   MsgBar "Setting New Filter", True
  522.   mrecFormRecordset.Filter = sFilterStr
  523.   Set recRecordset2 = mrecFormRecordset.OpenRecordset(mrecFormRecordset.Type) 'establish the filter
  524.   Set mrecFormRecordset = recRecordset2            'assign back to original recordset object
  525.   'everything must be okay so redisplay form on 1st record
  526.   mlNumRows = GetNumbRecs(mrecFormRecordset)         'query numb of recs
  527.   SetScrollBar
  528.   hsclCurrRow.VALUE = 0
  529.   DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  530.   mbDataChanged = False
  531.   Screen.MousePointer = vbDefault
  532.   MsgBar gsNULL_STR, False
  533.   Exit Sub
  534. FilterErr:
  535.   ShowError
  536.   Set mrecFormRecordset = recRecordset1            're-assign back to original
  537.   mrecFormRecordset.Bookmark = sBookMark           'go back to original record
  538.   Exit Sub
  539. End Sub
  540. Private Sub cmdFind_Click()
  541.   On Error GoTo FindErr
  542.   Dim i As Integer
  543.   Dim sBookMark As String
  544.   Dim sTmp As String
  545.   'load the column names into the find form
  546.   If mfrmFind.lstFields.ListCount = 0 Then
  547.     For i = 0 To mrecFormRecordset.Fields.Count - 1
  548.       mfrmFind.lstFields.AddItem Mid(lblFieldName(i).Caption, 1, Len(lblFieldName(i).Caption) - 1)
  549.     Next
  550.   End If
  551. FindStart:
  552.   'reset the flags
  553.   gbFindFailed = False
  554.   gbFromTableView = False
  555.   mbNotFound = False
  556.   MsgBar "Enter Search Parameters", False
  557.   mfrmFind.Show vbModal
  558.   MsgBar "Searching for New Record", True
  559.   If gbFindFailed = True Then   'find cancelled
  560.     GoTo AfterWhile
  561.   End If
  562.   SetHourglass
  563.   i = mfrmFind.lstFields.ListIndex
  564.   sBookMark = mrecFormRecordset.Bookmark
  565.   'search for the record
  566.   If mrecFormRecordset(i).Type = dbText Or mrecFormRecordset(i).Type = dbMemo Then
  567.     sTmp = AddBrackets((mrecFormRecordset(i).Name)) & " " & gsFindOp & " '" & gsFindExpr & "'"
  568.   Else
  569.     sTmp = AddBrackets((mrecFormRecordset(i).Name)) + gsFindOp + gsFindExpr
  570.   End If
  571.   Select Case gnFindType
  572.     Case 0
  573.       mrecFormRecordset.FindFirst sTmp
  574.     Case 1
  575.       mrecFormRecordset.FindNext sTmp
  576.     Case 2
  577.       mrecFormRecordset.FindPrevious sTmp
  578.     Case 3
  579.       mrecFormRecordset.FindLast sTmp
  580.   End Select
  581.   mbNotFound = mrecFormRecordset.NoMatch
  582. AfterWhile:
  583.   Screen.MousePointer = vbDefault
  584.   If gbFindFailed = True Then   'go back to original row
  585.     mrecFormRecordset.Bookmark = sBookMark
  586.   ElseIf mbNotFound Then
  587.     Beep
  588.     MsgBox "Record Not Found", 48
  589.     mrecFormRecordset.Bookmark = sBookMark
  590.     GoTo FindStart
  591.   Else
  592.     sBookMark = mrecFormRecordset.Bookmark  'save the new position
  593.     'now we need to reposition the scrollbar to reflect the move
  594.     If mlNumRows > 99 Then
  595.       hsclCurrRow.VALUE = (mrecFormRecordset.PercentPosition * mlNumRows) / 100 + 1
  596.     Else
  597.       hsclCurrRow.VALUE = mrecFormRecordset.PercentPosition
  598.     End If
  599.     mrecFormRecordset.Bookmark = sBookMark
  600.   End If
  601.   DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  602.   mbDataChanged = False
  603.   MsgBar gsNULL_STR, False
  604.   Exit Sub
  605. FindErr:
  606.   Screen.MousePointer = vbDefault
  607.   If Err <> gnEOF_ERR Then
  608.     ShowError
  609.     Exit Sub
  610.   Else
  611.     mbNotFound = True
  612.     Resume Next
  613.   End If
  614. End Sub
  615. Private Sub Form_Load()
  616.    Dim nStartPt As Integer        'starting point of table name
  617.    Dim nEndPt As Integer          'ending point of table name
  618.    Dim sTmp As String             'temp recordset name string
  619.    Dim sWhere As String           'where clause
  620.    Dim nFieldType As Integer      'field type of current field
  621.    Dim i As Integer, j As Integer 'indexes
  622.    Dim qdfTmp As QueryDef
  623.    Dim bParmQry As Integer
  624.    Dim prpTmp As Property         'user defined property object
  625.    Dim Start1 As Long, Finish1 As Long, Start2 As Long, Finish2 As Long
  626.    On Error GoTo DynasetErr
  627.    SetHourglass
  628.    'set the message bar
  629.    If frmMDI.optDynaset.VALUE = True Then
  630.      MsgBar "Opening Dynaset", True
  631.    ElseIf frmMDI.optSnapshot.VALUE = True Then
  632.      MsgBar "Opening Snapshot", True
  633.    ElseIf frmMDI.optPassThru.VALUE = True Then
  634.      MsgBar "Opening PassThru Snapshot", True
  635.    Else
  636.      'must be set to table so we need to change it
  637.      'because this form only handles dynasets and snapshots
  638.      frmMDI.optDynaset.VALUE = True
  639.      MsgBar "Opening Dynaset", True
  640.    End If
  641.    'assign the temp string with the select statement
  642.    'if it is not empty, otherwise, use the table list name
  643.    If gbFromSQL = True Then
  644.      If Len(gsDynaString) = 0 Then
  645.        sTmp = frmSQL.txtSQLStatement
  646.      Else
  647.        sTmp = gsDynaString
  648.      End If
  649.      Set qdfTmp = gdbCurrentDB.CreateQueryDef(gsNULL_STR, sTmp)
  650.      If qdfTmp.PARAMETERS.Count > 0 Then
  651.        bParmQry = True
  652.      End If
  653.    ElseIf Len(gsTableDynaFilter) > 0 Then
  654.      sTmp = gsTableDynaFilter
  655.    Else
  656.      If frmTables.optTables.VALUE = True Then
  657.        sTmp = StripConnect(frmTables.lstTables.TEXT)
  658.      Else
  659.        sTmp = frmTables.lstQueryDefs.TEXT
  660.        Set qdfTmp = gdbCurrentDB.QueryDefs(frmTables.lstQueryDefs.TEXT)
  661.        If qdfTmp.PARAMETERS.Count > 0 Then
  662.          bParmQry = True
  663.        End If
  664.      End If
  665.    End If
  666.    'attemp to open the recordset
  667.    If bParmQry = True Then
  668.      'parameterized query
  669.      SetParams qdfTmp
  670.      Start1 = OSTimeGetTime()
  671.      Set mrecFormRecordset = qdfTmp.OpenRecordset( _
  672.                              IIf(frmMDI.optDynaset.VALUE = True, 2, 4) _
  673.                              , IIf(frmMDI.optPassThru.VALUE = True, dbSQLPassThrough, 0))
  674.      
  675.    Else
  676.      Start1 = OSTimeGetTime()
  677.      If gbFromSQL = True Then
  678.        If frmMDI.optPassThru.VALUE = True Then
  679.          'need to open a temp querydef so that
  680.          'the PercentPosition prop will be available
  681.          'on the passthrough recordset
  682.          Set qdfTmp = gdbCurrentDB.CreateQueryDef(gsNULL_STR, sTmp)
  683.          'need to set the connect property so a passthorugh querydef is created
  684.          qdfTmp.Connect = gdbCurrentDB.Connect
  685.          Set mrecFormRecordset = qdfTmp.OpenRecordset(dbOpenSnapshot)
  686.        Else
  687.          If frmMDI.optDynaset.VALUE = True Then
  688.            Set mrecFormRecordset = gdbCurrentDB.OpenRecordset(sTmp, dbOpenDynaset)
  689.          Else
  690.            Set mrecFormRecordset = gdbCurrentDB.OpenRecordset(sTmp, dbOpenSnapshot)
  691.          End If
  692.        End If
  693.      Else
  694.        If frmMDI.optPassThru.VALUE = True Then
  695.          sTmp = "select * from " & StripOwner(sTmp)
  696.          'need to open a temp querydef so that
  697.          'the PercentPosition prop will be available
  698.          'on the passthrough recordset
  699.          Set qdfTmp = gdbCurrentDB.CreateQueryDef(gsNULL_STR, sTmp)
  700.          Set mrecFormRecordset = qdfTmp.OpenRecordset(dbOpenSnapshot, dbSQLPassThrough)
  701.        Else
  702.          If frmMDI.optDynaset.VALUE = True Then
  703.            Set mrecFormRecordset = gdbCurrentDB.OpenRecordset(sTmp, dbOpenDynaset)
  704.          Else
  705.            Set mrecFormRecordset = gdbCurrentDB.OpenRecordset(sTmp, dbOpenSnapshot)
  706.          End If
  707.        End If
  708.      End If
  709.    End If
  710.    Finish1 = OSTimeGetTime()
  711.    'set the locking type
  712.    If gsDataType = gsJETMDB And mrecFormRecordset.Type <> dbOpenSnapshot Then
  713.      mrecFormRecordset.LockEdits = gnMULocking
  714.    End If
  715.    'parse off table name to store in msTblName
  716.    sWhere = gsNULL_STR
  717.    nStartPt = InStr(1, UCase(sTmp), "FROM")
  718.    If nStartPt > 0 Then
  719.      'must be a "select from" statement
  720.      nStartPt = nStartPt + 5
  721.      For nEndPt = nStartPt To Len(sTmp)
  722.        'search for a nStartPtace or the end of sTmp
  723.        If Mid(sTmp, nEndPt, 1) = " " Or Mid(sTmp, nEndPt, 1) = Chr(13) Then
  724.          'get where clause if there is one
  725.          sWhere = Mid(sTmp, nStartPt, Len(sTmp) - nStartPt + 1)
  726.          Exit For
  727.        End If
  728.      Next
  729.      msTableName = Mid(sTmp, nStartPt, nEndPt - nStartPt)
  730.      If Len(sWhere) = 0 Then sWhere = msTableName
  731.    Else
  732.      'must be a table name only
  733.      msTableName = sTmp
  734.      sWhere = msTableName
  735.    End If
  736.    'get the row count
  737.    Start2 = OSTimeGetTime()
  738.    mlNumRows = GetNumbRecs(mrecFormRecordset)          'query numb of recs
  739.    Finish2 = OSTimeGetTime()
  740.    SetScrollBar
  741.    'load the controls on the recordset form
  742.    lblFieldName(0).Visible = True
  743.    txtFieldData(0).Visible = True
  744.    nFieldType = mrecFormRecordset(0).Type
  745.    txtFieldData(0).Width = GetFieldWidth(nFieldType)
  746.    If nFieldType = dbText Then txtFieldData(0).MaxLength = mrecFormRecordset(0).Size
  747.    txtFieldData(0).TabIndex = 0
  748.    For i = 1 To mrecFormRecordset.Fields.Count - 1
  749.      picFields.Height = picFields.Height + gnCTLARRAYHEIGHT
  750.      Load lblFieldName(i)
  751.      lblFieldName(i).TOP = lblFieldName(i - 1).TOP + gnCTLARRAYHEIGHT
  752.      lblFieldName(i).Visible = True
  753.      Load txtFieldData(i)
  754.      txtFieldData(i).TOP = txtFieldData(i - 1).TOP + gnCTLARRAYHEIGHT
  755.      txtFieldData(i).Visible = True
  756.      nFieldType = mrecFormRecordset.Fields(i).Type
  757.      txtFieldData(i).Width = GetFieldWidth(nFieldType)
  758.      If nFieldType = dbText Then txtFieldData(i).MaxLength = mrecFormRecordset(i).Size
  759.      txtFieldData(i).TabIndex = i
  760.    Next
  761.    'resize main window
  762.    Me.Width = 5520
  763.    If i <= 10 Then
  764.      Me.Height = ((i + 1) * gnCTLARRAYHEIGHT) + 1600
  765.    Else
  766.      Me.Height = 4368
  767.      Me.Width = Me.Width + 260
  768.      vsbScrollBar.Visible = True
  769.      vsbScrollBar.MIN = 1080
  770.      vsbScrollBar.MAX = 1080 - (i * gnCTLARRAYHEIGHT) + 2240
  771.    End If
  772.    'display the field names
  773.    For i = 0 To mrecFormRecordset.Fields.Count - 1
  774.      lblFieldName(i).Caption = mrecFormRecordset(i).Name & ":"
  775.    Next
  776.    DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  777.    mbDataChanged = False
  778.    If mrecFormRecordset.Type = dbOpenDynaset Then
  779.      If Len(gsTableDynaFilter) > 0 Then
  780.        Me.Caption = "Filtered Dynaset: " & msTableName
  781.      Else
  782.        Me.Caption = "Dynaset: " & msTableName
  783.      End If
  784.    Else
  785.      If Len(gsTableDynaFilter) > 0 Then
  786.        Me.Caption = "Filtered Snapshot: " & msTableName
  787.      ElseIf frmMDI.optPassThru.VALUE = True Then
  788.        Me.Caption = "PassThru Snapshot: " & msTableName
  789.      Else
  790.        Me.Caption = "Snapshot: " & msTableName
  791.      End If
  792.    End If
  793.    Me.Left = 1000
  794.    Me.TOP = 1000
  795.    If frmMDI.mnuPShowPerf.Checked = True Then
  796.      Me.Show
  797.      MsgBox CStr(mlNumRows) & " rows found in " & (Finish1 - Start1) / 1000 & " seconds!" & gsNewLine & (Finish2 - Start2) / 1000 & " seconds to Get Record Count!", 48
  798.    End If
  799.    Screen.MousePointer = vbDefault
  800.    MsgBar gsNULL_STR, False
  801.    Exit Sub
  802. DynasetErr:
  803.    ShowError
  804.    Unload Me
  805.    Exit Sub
  806. End Sub
  807. Private Sub Form_Resize()
  808.   On Error Resume Next
  809.   Dim nHeight As Integer
  810.   Dim i As Integer
  811.   Dim nTotWidth As Integer
  812.   Const nHeightFactor = 1420
  813.   If WindowState <> 1 Then   'not minimized
  814.     MsgBar "Resizing Form", True
  815.     'make sure the form is lined up on a field
  816.     nHeight = Height
  817.     If (nHeight - nHeightFactor) Mod gnCTLARRAYHEIGHT <> 0 Then
  818.       Me.Height = ((nHeight - nHeightFactor) \ gnCTLARRAYHEIGHT) * gnCTLARRAYHEIGHT + nHeightFactor
  819.     End If
  820.     'resize the status bar
  821.     picMoveButtons.TOP = Me.Height - 650
  822.     'resize the scrollbar
  823.     vsbScrollBar.Height = picMoveButtons.TOP - (picViewButtons.TOP - picFldHdr.Height) - 1320
  824.     vsbScrollBar.Left = Me.Width - 360
  825.     If mrecFormRecordset.Fields.Count > 10 Then
  826.       picFields.Width = Me.Width - 260
  827.       nTotWidth = vsbScrollBar.Left - 20
  828.     Else
  829.       picFields.Width = Me.Width - 20
  830.       nTotWidth = Me.Width - 50
  831.     End If
  832.     picFldHdr.Width = Me.Width - 20
  833.     'widen the fields if possible
  834.     For i = 0 To mrecFormRecordset.Fields.Count - 1
  835.       lblFieldName(i).Width = 0.3 * nTotWidth
  836.       txtFieldData(i).Left = lblFieldName(i).Width + 20
  837.       If mrecFormRecordset(i).Type = dbText Or mrecFormRecordset(i).Type = dbMemo Then
  838.         txtFieldData(i).Width = 0.7 * nTotWidth - 250
  839.       End If
  840.     Next
  841.     lblFieldValue.Left = txtFieldData(0).Left
  842.     hsclCurrRow.Width = picMoveButtons.Width \ 2
  843.     lblStatus.Width = picMoveButtons.Width \ 2
  844.     lblStatus.Left = hsclCurrRow.Width + 10
  845.   End If
  846.   MsgBar gsNULL_STR, False
  847. End Sub
  848. Private Sub Form_Unload(Cancel As Integer)
  849.   On Error Resume Next
  850.   Unload mfrmFind   'get rid of attached find form
  851.   mrecFormRecordset.Close          'close the form recordset
  852.   DBEngine.Idle dbFreeLocks
  853.   MsgBar gsNULL_STR, False
  854. End Sub
  855. Private Sub cmdProperties_Click()
  856.   ShowProperties "Recordset", mrecFormRecordset
  857. End Sub
  858. Private Sub cmdSort_Click()
  859.   On Error GoTo SortErr
  860.   Dim sBookMark As String
  861.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  862.   Dim SortStr As String
  863.   sBookMark = mrecFormRecordset.Bookmark        'save the bookmark
  864.   Set recRecordset1 = mrecFormRecordset            'save the recordset
  865.   SortStr = InputBox("Enter Sort Column:")
  866.   If Len(SortStr) = 0 Then Exit Sub
  867.   SetHourglass
  868.   MsgBar "Setting New Sort Order", True
  869.   mrecFormRecordset.Sort = SortStr
  870.   'establish the Sort
  871.   Set recRecordset2 = mrecFormRecordset.OpenRecordset(mrecFormRecordset.Type)
  872.   Set mrecFormRecordset = recRecordset2            'assign back to original recordset object
  873.   'everything must be okay so redisplay form on 1st record
  874.   mlNumRows = GetNumbRecs(mrecFormRecordset)          'query numb of recs
  875.   hsclCurrRow.VALUE = 0
  876.   DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  877.   mbDataChanged = False
  878.   Screen.MousePointer = vbDefault
  879.   MsgBar gsNULL_STR, False
  880.   Exit Sub
  881. SortErr:
  882.   ShowError
  883.   Set mrecFormRecordset = recRecordset1            're-assign back to original
  884.   mrecFormRecordset.Bookmark = sBookMark        'go back to original record
  885.   Exit Sub
  886. End Sub
  887. Private Sub cmdUpdate_Click()
  888.   On Error GoTo UpdateErr
  889.   Dim nDelay As Long
  890.   Dim nRetryCnt As Integer
  891.   SetHourglass
  892. RetryUpd:
  893.   mrecFormRecordset.UPDATE
  894.   If gbTransPending Then gbDBChanged = True
  895.   If mbAddNewFlag = True Then
  896.     mlNumRows = mlNumRows + 1
  897.     SetScrollBar
  898.     'move to the new record
  899.     mrecFormRecordset.Bookmark = mrecFormRecordset.LastModified
  900.   End If
  901.   picChangeButtons.Visible = False
  902.   picViewButtons.Visible = True
  903.   hsclCurrRow.Enabled = True
  904.   mbEditFlag = False
  905.   mbAddNewFlag = False
  906.   DisplayCurrentRecord Me, mrecFormRecordset, mlNumRows, mbAddNewFlag
  907.   mbDataChanged = False
  908.   DBEngine.Idle dbFreeLocks
  909.   Screen.MousePointer = vbDefault
  910.   Exit Sub
  911. UpdateErr:
  912.   'check for locked error
  913.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  914.     nRetryCnt = nRetryCnt + 1
  915.     mrecFormRecordset.Bookmark = mrecFormRecordset.Bookmark   'Cancel the update
  916.     DBEngine.Idle dbFreeLocks
  917.     nDelay = Timer
  918.     'Wait gnMUDelay seconds
  919.     While Timer - nDelay < gnMUDelay
  920.       'do nothing
  921.     Wend
  922.     Resume RetryUpd
  923.   Else
  924.     ShowError
  925.     Exit Sub
  926.   End If
  927. End Sub
  928. Private Sub SetScrollBar()
  929.   If mlNumRows < 2 Then
  930.     hsclCurrRow.MAX = 100
  931.     hsclCurrRow.SmallChange = 100
  932.     hsclCurrRow.LargeChange = 100
  933.   ElseIf mlNumRows > 32767 Then
  934.     hsclCurrRow.MAX = 32767
  935.     hsclCurrRow.SmallChange = 1
  936.     hsclCurrRow.LargeChange = 1000
  937.   ElseIf mlNumRows > 99 Then
  938.     hsclCurrRow.MAX = mlNumRows
  939.     hsclCurrRow.SmallChange = 1
  940.     hsclCurrRow.LargeChange = mlNumRows \ 20
  941.   Else
  942.     'must be between 2 and 100
  943.     hsclCurrRow.MAX = 100
  944.     hsclCurrRow.SmallChange = 100 \ (mlNumRows - 1)
  945.     hsclCurrRow.LargeChange = (100 \ (mlNumRows - 1)) * 10
  946.   End If
  947. End Sub
  948.