home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / VISDATA / DATAFORM.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-12  |  25.1 KB  |  844 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmDataControl 
  4.    ClientHeight    =   2160
  5.    ClientLeft      =   1230
  6.    ClientTop       =   3075
  7.    ClientWidth     =   5775
  8.    HelpContextID   =   2016122
  9.    Icon            =   "DATAFORM.frx":0000
  10.    LinkTopic       =   "Form2"
  11.    LockControls    =   -1  'True
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   2160
  14.    ScaleWidth      =   5775
  15.    ShowInTaskbar   =   0   'False
  16.    Tag             =   "Recordset"
  17.    Begin VB.PictureBox picButtons 
  18.       Align           =   1  'Align Top
  19.       Appearance      =   0  'Flat
  20.       BorderStyle     =   0  'None
  21.       ForeColor       =   &H80000008&
  22.       Height          =   600
  23.       Left            =   0
  24.       ScaleHeight     =   600
  25.       ScaleWidth      =   5775
  26.       TabIndex        =   0
  27.       Top             =   0
  28.       Width           =   5772
  29.       Begin VB.CommandButton cmdCancelAdd 
  30.          Caption         =   "
  31. (&A)"
  32.          Height          =   330
  33.          Left            =   -15
  34.          MaskColor       =   &H00000000&
  35.          TabIndex        =   13
  36.          Top             =   0
  37.          Visible         =   0   'False
  38.          Width           =   960
  39.       End
  40.       Begin VB.CommandButton cmdRefresh 
  41.          Caption         =   "
  42. (&R)"
  43.          Height          =   330
  44.          Left            =   3852
  45.          MaskColor       =   &H00000000&
  46.          TabIndex        =   12
  47.          Top             =   0
  48.          Width           =   960
  49.       End
  50.       Begin VB.CommandButton cmdFind 
  51.          Caption         =   "
  52. (&F)"
  53.          Height          =   330
  54.          Left            =   2880
  55.          MaskColor       =   &H00000000&
  56.          TabIndex        =   5
  57.          Top             =   0
  58.          Width           =   960
  59.       End
  60.       Begin VB.CommandButton cmdClose 
  61.          Cancel          =   -1  'True
  62.          Caption         =   "
  63. (&C)"
  64.          Height          =   330
  65.          Left            =   4800
  66.          MaskColor       =   &H00000000&
  67.          TabIndex        =   4
  68.          Top             =   0
  69.          Width           =   960
  70.       End
  71.       Begin VB.CommandButton cmdDelete 
  72.          Caption         =   "
  73. (&D)"
  74.          Height          =   330
  75.          Left            =   1920
  76.          MaskColor       =   &H00000000&
  77.          TabIndex        =   3
  78.          Top             =   0
  79.          Width           =   960
  80.       End
  81.       Begin VB.CommandButton cmdAdd 
  82.          Caption         =   "
  83. (&A)"
  84.          Height          =   330
  85.          Left            =   0
  86.          MaskColor       =   &H00000000&
  87.          TabIndex        =   2
  88.          Top             =   0
  89.          Width           =   960
  90.       End
  91.       Begin VB.CommandButton cmdUpdate 
  92.          Caption         =   "
  93. (&U)"
  94.          Height          =   330
  95.          Left            =   960
  96.          MaskColor       =   &H00000000&
  97.          TabIndex        =   1
  98.          Top             =   0
  99.          Width           =   960
  100.       End
  101.       Begin VB.Label lblFieldHeader 
  102.          Caption         =   "
  103.          Height          =   255
  104.          Left            =   120
  105.          TabIndex        =   15
  106.          Top             =   360
  107.          Width           =   1215
  108.       End
  109.       Begin VB.Label lblFieldValue 
  110.          Caption         =   "
  111.          Height          =   255
  112.          Left            =   1680
  113.          TabIndex        =   14
  114.          Top             =   360
  115.          Width           =   2655
  116.       End
  117.    End
  118.    Begin VB.Data datDataCtl 
  119.       Align           =   2  'Align Bottom
  120.       Connect         =   "Access"
  121.       DatabaseName    =   ""
  122.       DefaultCursorType=   0  '
  123.       DefaultType     =   2  '
  124.  ODBC
  125.       Exclusive       =   0   'False
  126.       Height          =   345
  127.       Left            =   0
  128.       Options         =   0
  129.       ReadOnly        =   0   'False
  130.       RecordsetType   =   1  'Dynaset
  131.       RecordSource    =   ""
  132.       Tag             =   "OLE"
  133.       Top             =   1815
  134.       Width           =   5772
  135.    End
  136.    Begin VB.VScrollBar vsbScrollBar 
  137.       Height          =   2440
  138.       LargeChange     =   3000
  139.       Left            =   7665
  140.       SmallChange     =   300
  141.       TabIndex        =   11
  142.       Top             =   630
  143.       Visible         =   0   'False
  144.       Width           =   255
  145.    End
  146.    Begin VB.PictureBox picFields 
  147.       Appearance      =   0  'Flat
  148.       BorderStyle     =   0  'None
  149.       ForeColor       =   &H80000008&
  150.       Height          =   1065
  151.       Left            =   0
  152.       ScaleHeight     =   1056.479
  153.       ScaleMode       =   0  'User
  154.       ScaleWidth      =   7600.264
  155.       TabIndex        =   6
  156.       TabStop         =   0   'False
  157.       Top             =   600
  158.       Width           =   7605
  159.       Begin VB.TextBox txtFieldData 
  160.          BackColor       =   &H00FFFFFF&
  161.          DataSource      =   "datDataCtl"
  162.          ForeColor       =   &H00000000&
  163.          Height          =   285
  164.          Index           =   0
  165.          Left            =   1665
  166.          TabIndex        =   9
  167.          Top             =   0
  168.          Visible         =   0   'False
  169.          Width           =   3255
  170.       End
  171.       Begin VB.CheckBox chkFieldData 
  172.          DataSource      =   "datDataCtl"
  173.          Height          =   282
  174.          Index           =   0
  175.          Left            =   1680
  176.          MaskColor       =   &H00000000&
  177.          TabIndex        =   8
  178.          Top             =   735
  179.          Visible         =   0   'False
  180.          Width           =   3270
  181.       End
  182.       Begin VB.PictureBox picFieldData 
  183.          BackColor       =   &H00FFFFFF&
  184.          DataSource      =   "datDataCtl"
  185.          Height          =   285
  186.          Index           =   0
  187.          Left            =   1680
  188.          ScaleHeight     =   225
  189.          ScaleWidth      =   3210
  190.          TabIndex        =   7
  191.          Top             =   360
  192.          Visible         =   0   'False
  193.          Width           =   3270
  194.       End
  195.       Begin VB.OLE oleFieldData 
  196.          BackColor       =   &H00FFFFFF&
  197.          DataSource      =   "datDataCtl"
  198.          DisplayType     =   1  'Icon
  199.          Height          =   300
  200.          Index           =   0
  201.          Left            =   1680
  202.          TabIndex        =   16
  203.          Top             =   360
  204.          Visible         =   0   'False
  205.          Width           =   3255
  206.       End
  207.       Begin VB.Label lblFieldName 
  208.          ForeColor       =   &H00000000&
  209.          Height          =   195
  210.          Index           =   0
  211.          Left            =   105
  212.          TabIndex        =   10
  213.          Top             =   0
  214.          Visible         =   0   'False
  215.          Width           =   300
  216.       End
  217.    End
  218.    Begin MSComDlg.CommonDialog dlgCMD1 
  219.       Left            =   2415
  220.       Top             =   1755
  221.       _ExtentX        =   847
  222.       _ExtentY        =   847
  223.       FilterIndex     =   1019
  224.       FontSize        =   8.49966e-19
  225.    End
  226. Attribute VB_Name = "frmDataControl"
  227. Attribute VB_GlobalNameSpace = False
  228. Attribute VB_Creatable = False
  229. Attribute VB_PredeclaredId = True
  230. Attribute VB_Exposed = False
  231. Option Explicit
  232. '>>>>>>>>>>>>>>>>>>>>>>>>
  233. Const BUTTON1 = "
  234. (&C)"
  235. Const BUTTON2 = "
  236. (&U)"
  237. Const BUTTON3 = "
  238. (&D)"
  239. Const BUTTON4 = "
  240. (&F)"
  241. Const BUTTON5 = "
  242. (&R)"
  243. Const BUTTON6 = "
  244. (&C)"
  245. Const BUTTON7 = "
  246. (&A)"
  247. Const Label1 = "
  248. Const Label2 = "
  249. Const MSG1 = "
  250. Const MSG2 = "
  251. Const MSG3 = "
  252.  Err 
  253. Const MSG4 = "
  254. Const MSG5 = "
  255. Const MSG6 = "
  256. Const MSG7 = "
  257. Const MSG8 = "
  258. Const MSG9 = "
  259. Const MSG10 = "
  260. Const MSG11 = "
  261. Const MSG12 = "  [
  262. '>>>>>>>>>>>>>>>>>>>>>>>>
  263. '============================================================================
  264.  table 
  265.  querydef
  266. '============================================================================
  267. Dim maFldArr() As Object
  268. Public mrsFormRecordset As Recordset
  269. Dim mvBookMark As Variant        '
  270. Dim mnNumFields As Integer       '
  271. Dim mlNumRows As Long            '
  272. Dim mbJustUsedFind As Boolean    '
  273. Dim mbResizing As Boolean        '
  274. Dim mbCancel As Boolean          '
  275. Dim mnFieldTop As Integer        '
  276. Const mnMSGBOX_TYPE = vbYesNo + vbQuestion
  277. Const mnCTLARRAYHEIGHT = 340
  278. Private Sub cmdAdd_Click()
  279.   On Error GoTo AddErr
  280.   datDataCtl.Recordset.AddNew
  281.   datDataCtl.Caption = MSG1
  282.   cmdCancelAdd.Visible = True
  283.   cmdAdd.Visible = False
  284.   If datDataCtl.Recordset.RecordCount <> 0 Then
  285.     mvBookMark = datDataCtl.Recordset.Bookmark
  286.     maFldArr(0).SetFocus
  287.   End If
  288.   Exit Sub
  289. AddErr:
  290.   ShowErrMsg
  291. End Sub
  292. Private Sub cmdCancelAdd_Click()
  293.   On Error Resume Next
  294.   mbCancel = True
  295.   If Len(mvBookMark) > 0 Then
  296.     datDataCtl.Recordset.Bookmark = mvBookMark
  297.   End If
  298. End Sub
  299. '----------------------------------------------------------
  300.  Data 
  301. '----------------------------------------------------------
  302. Sub datDataCtl_MouseUp(BUTTON As Integer, Shift As Integer, X As Single, Y As Single)
  303.   On Error GoTo DCPErr
  304.   Dim i As Integer
  305.   Dim recClone As Recordset
  306.   Dim sTmpRS As String
  307.   Dim sTmpDB As String
  308.   Dim sTmpTag As String
  309.   If BUTTON = 2 Then
  310.     Screen.MousePointer = vbHourglass
  311.     sTmpRS = datDataCtl.RecordSource
  312.     sTmpDB = datDataCtl.DatabaseName
  313.     sTmpTag = datDataCtl.Tag
  314.     Set gDataCtlObj = datDataCtl
  315.     frmDataCtlProp.Show vbModal
  316.     If Not gDataCtlObj Is Nothing Then
  317.       '
  318.       '
  319.       If (sTmpRS <> gDataCtlObj.RecordSource Or sTmpDB <> gDataCtlObj.DatabaseName) _
  320.          Or gDataCtlObj.Tag <> sTmpTag Then
  321.         '
  322.         For i = 0 To mnNumFields - 1
  323.           lblFieldName(i).Caption = vbNullString
  324.           maFldArr(i).DataField = vbNullString
  325.           maFldArr(i).Visible = False
  326.         Next
  327.       End If
  328.       datDataCtl.Refresh
  329.       If (sTmpRS <> gDataCtlObj.RecordSource Or sTmpDB <> gDataCtlObj.DatabaseName) _
  330.          Or gDataCtlObj.Tag <> sTmpTag Then
  331.         Set recClone = datDataCtl.Recordset.Clone()
  332.         If recClone.BOF = False And (datDataCtl.Options And dbForwardOnly) = 0 Then
  333.           recClone.MoveLast
  334.           mlNumRows = recClone.RecordCount
  335.         Else
  336.           mlNumRows = 0
  337.         End If
  338.         recClone.Close
  339.         LoadFields
  340.         SetRecNum
  341.       Else
  342.         '
  343.         '
  344.         Set mrsFormRecordset = datDataCtl.Recordset
  345.         '
  346.  SetRecNum
  347.         '
  348.  data 
  349.         If (datDataCtl.Options And dbForwardOnly) = dbForwardOnly Then
  350.           SetRecNum
  351.         End If
  352.       End If
  353.       gbSettingDataCtl = False
  354.       If gDataCtlObj.Tag <> sTmpTag Then
  355.         Form_Resize    '
  356.  left 
  357.       End If
  358.     End If
  359.   End If
  360.   Exit Sub
  361. DCPErr:
  362.   ShowError
  363.   Unload Me
  364. End Sub
  365. Private Sub Form_Unload(Cancel As Integer)
  366.   DBEngine.Idle dbFreeLocks
  367. End Sub
  368. Private Sub oleFieldData_MouseUp(Index As Integer, BUTTON As Integer, Shift As Integer, X As Single, Y As Single)
  369.   If BUTTON <> 2 Then Exit Sub
  370.  OLE 
  371.   oleFieldData(Index).InsertObjDlg
  372. End Sub
  373. Private Sub txtFieldData_KeyPress(Index As Integer, KeyAscii As Integer)
  374.   If KeyAscii = 13 Then
  375.     KeyAscii = 0
  376.     SendKeys "{Tab}"
  377.   End If
  378. End Sub
  379. Private Sub picFieldData_Click(Index As Integer)
  380.  picture 
  381.   If picFieldData(Index).Height <= 280 Then
  382.     picFieldData(Index).AutoSize = True
  383.   Else
  384.     picFieldData(Index).AutoSize = False
  385.     picFieldData(Index).Height = 280
  386.   End If
  387. End Sub
  388. Private Sub picFieldData_DblClick(Index As Integer)
  389.   On Error GoTo PicErr
  390.   With dlgCMD1
  391.     .Filter = "
  392.  (*.bmp)|*.bmp|
  393.  (*.ico)|*.ico|
  394.  (*.wmf)|*.wmf|
  395.  (*.*)|*.*"
  396.     .DialogTitle = MSG2
  397.     .FilterIndex = 1
  398.     .ShowOpen
  399.     If Len(.FileName) > 0 Then
  400.       picFieldData(Index).Picture = LoadPicture(.FileName)
  401.     End If
  402.   End With
  403.   Exit Sub
  404. PicErr:
  405.   ShowErrMsg
  406.   Exit Sub
  407. End Sub
  408. Private Sub cmdClose_Click()
  409.   On Error Resume Next
  410.   Unload Me
  411. End Sub
  412. Private Sub vsbScrollBar_Change()
  413.   Dim nCurrVal As Integer
  414.   nCurrVal = vsbScrollBar
  415.   If (nCurrVal - mnFieldTop) Mod mnCTLARRAYHEIGHT = 0 Then
  416.     picFields.Top = nCurrVal
  417.   Else
  418.     picFields.Top = ((nCurrVal - mnFieldTop) \ mnCTLARRAYHEIGHT) * mnCTLARRAYHEIGHT + mnFieldTop
  419.   End If
  420. End Sub
  421. Private Sub datDataCtl_Error(DataErr As Integer, Response As Integer)
  422.   If DataErr = 481 Then  '
  423.     Response = vbDataErrContinue
  424.   Else
  425.     MsgBox MSG3 & Error(DataErr)
  426.   End If
  427. End Sub
  428. Private Sub datDataCtl_RePosition()
  429.   On Error GoTo RepErr
  430.   Dim sBookMark As String
  431.   Dim recClone As Recordset
  432.  data 
  433.   If gbSettingDataCtl Then Exit Sub
  434.  AddNew 
  435.  cmdAdd_Click 
  436.  AddNew
  437.   If (datDataCtl.Recordset.RecordCount = 0) And _
  438.      (datDataCtl.EditMode <> dbEditAdd) And _
  439.       datDataCtl.Recordset.Updatable Then
  440.     Call cmdAdd_Click
  441.     Exit Sub
  442.   End If
  443.   SetRecNum
  444.   Exit Sub
  445. RepErr:
  446.   ShowErrMsg
  447.   Exit Sub
  448. End Sub
  449. Private Sub datDataCtl_Validate(Action As Integer, Save As Integer)
  450.   On Error GoTo ValErr
  451.   If mbCancel Then
  452.     Save = False
  453.     mbCancel = False
  454.     Exit Sub
  455.   End If
  456. addnew
  457.   If Action < 5 Then
  458.     If Save Then       '
  459.       If datDataCtl.EditMode = dbEditAdd Then
  460.         If MsgBox(MSG4, mnMSGBOX_TYPE) = vbYes Then
  461.           mlNumRows = mlNumRows + 1
  462.         Else
  463.           Save = False
  464.         End If
  465.       Else
  466.         If MsgBox(MSG5, mnMSGBOX_TYPE) <> vbYes Then
  467.           Save = False        '
  468.         End If
  469.       End If
  470.     End If
  471.   End If
  472.   Select Case Action
  473.     Case vbDataActionMoveFirst
  474.       '
  475.     Case vbDataActionMovePrevious
  476.       '
  477.     Case vbDataActionMoveNext
  478.       '
  479.     Case vbDataActionMoveLast
  480.       '
  481.     Case vbDataActionAddNew
  482.       '
  483.     Case vbDataActionUpdate
  484.        '
  485.  cmdUpdate_click 
  486.     Case vbDataActionDelete
  487.       '
  488.     Case vbDataActionFind
  489.       '
  490.  reposition 
  491.       mbJustUsedFind = True
  492.     Case vbDataActionBookmark
  493.       '
  494.     Case vbDataActionClose, vbDataActionUnload
  495.       If Save Then
  496.         If MsgBox(MSG6, mnMSGBOX_TYPE) <> vbYes Then
  497.           Save = False
  498.         End If
  499.       End If
  500.   End Select
  501.   Exit Sub
  502. ValErr:
  503.   ShowErrMsg
  504.   Exit Sub
  505. End Sub
  506. Private Sub cmdDelete_Click()
  507.   On Error GoTo DELErr
  508.   If MsgBox(MSG7, mnMSGBOX_TYPE) = vbYes Then
  509.     datDataCtl.Recordset.Delete
  510.     mlNumRows = mlNumRows - 1
  511.     datDataCtl.Recordset.MoveNext
  512.     '
  513.     If datDataCtl.Recordset.RecordCount > 0 Then datDataCtl.Recordset.MoveLast
  514.     maFldArr(0).SetFocus
  515.   End If
  516.   Exit Sub
  517. DELErr:
  518.   ShowErrMsg
  519.   Exit Sub
  520. End Sub
  521. Private Sub cmdFind_Click()
  522.   On Error GoTo FindErr
  523.   Dim sBookMark As String
  524.   Dim sFindStr As String
  525.   If datDataCtl.Recordset.Type = dbOpenTable Then
  526.     sFindStr = InputBox(MSG8)
  527.   Else
  528.     sFindStr = InputBox(MSG9)
  529.   End If
  530.   If Len(sFindStr) = 0 Then Exit Sub
  531.   If datDataCtl.Recordset.RecordCount > 0 Then
  532.     sBookMark = datDataCtl.Recordset.Bookmark
  533.   End If
  534.   If datDataCtl.Recordset.Type = dbOpenTable Then
  535.     datDataCtl.Recordset.Seek "=", sFindStr
  536.   Else
  537.     datDataCtl.Recordset.FindFirst sFindStr
  538.   End If
  539.   If datDataCtl.Recordset.NoMatch And Len(sBookMark) > 0 Then
  540.     datDataCtl.Recordset.Bookmark = sBookMark
  541.   End If
  542.   maFldArr(0).SetFocus
  543.   Exit Sub
  544. FindErr:
  545.   ShowErrMsg
  546.   maFldArr(0).SetFocus
  547.   Exit Sub
  548. End Sub
  549. Private Sub Form_Load()
  550.   On Error GoTo LoadErr
  551.   cmdCancelAdd.Caption = BUTTON1
  552.   cmdUpdate.Caption = BUTTON2
  553.   cmdDelete.Caption = BUTTON3
  554.   cmdFind.Caption = BUTTON4
  555.   cmdRefresh.Caption = BUTTON5
  556.   cmdClose.Caption = BUTTON6
  557.   cmdAdd.Caption = BUTTON7
  558.   lblFieldHeader.Caption = Label1
  559.   lblFieldValue.Caption = Label2
  560.   'mrsFormRecordset 
  561.   With mrsFormRecordset
  562.     If .Type = dbOpenTable Then
  563.       '
  564.       If gdbCurrentDB.TableDefs(.Name).Indexes.Count > 0 Then
  565.         .Index = gdbCurrentDB.TableDefs(.Name).Indexes(0).Name
  566.       End If
  567.     End If
  568.     If .RecordCount > 0 Then
  569.       '
  570. recordcount
  571.       .MoveNext
  572.       .MovePrevious
  573.     End If
  574.   End With
  575.   Set datDataCtl.Recordset = mrsFormRecordset
  576.   Me.Width = 5868
  577.   LoadFields
  578.   Me.Show
  579.   maFldArr(0).SetFocus
  580.   Exit Sub
  581. LoadErr:
  582.   ShowErrMsg
  583.   Unload Me
  584. End Sub
  585. Private Sub Form_Resize()
  586.   On Error Resume Next
  587.   If gbSettingDataCtl Then Exit Sub
  588.   If mbResizing Then Exit Sub
  589.   Dim nHeight As Integer
  590.   Dim i As Integer
  591.   Dim nTotalWidth As Integer
  592.   mbResizing = True
  593.   If Me.WindowState <> 1 And lblFieldName(0).Visible Then '
  594.     '
  595.     nHeight = Me.Height
  596.     If (nHeight - 1320) Mod mnCTLARRAYHEIGHT <> 0 Then
  597.       Me.Height = ((nHeight - 1280) \ mnCTLARRAYHEIGHT) * mnCTLARRAYHEIGHT + 1280
  598.     End If
  599.     '
  600.     datDataCtl.Top = Me.Height - 650
  601.     '
  602.     vsbScrollBar.Height = Me.Height - 1300
  603.     vsbScrollBar.Left = Me.Width - 360
  604.     If mrsFormRecordset.Fields.Count > 10 Then
  605.       picFields.Width = Me.Width - 260
  606.       nTotalWidth = vsbScrollBar.Left - 20
  607.     Else
  608.       picFields.Width = Me.Width - 20
  609.       nTotalWidth = Me.Width - 50
  610.     End If
  611.     picButtons.Width = Me.Width - 20
  612.     '
  613.     For i = 0 To mrsFormRecordset.Fields.Count - 1
  614.       lblFieldName(i).Width = 0.3 * nTotalWidth - 100
  615.       maFldArr(i).Left = lblFieldName(i).Width + 200
  616.       If datDataCtl.Recordset.Fields(i).Type > 9 Then
  617.         maFldArr(i).Width = 0.7 * nTotalWidth - 270
  618.       End If
  619.     Next
  620.     lblFieldValue.Left = maFldArr(0).Left
  621.   End If
  622.   mbResizing = False
  623. End Sub
  624. Private Function GetFieldWidth(rnType As Integer)
  625.   Select Case rnType
  626.     Case dbBoolean
  627.       GetFieldWidth = 850
  628.     Case dbByte
  629.       GetFieldWidth = 650
  630.     Case dbInteger
  631.       GetFieldWidth = 900
  632.     Case dbLong
  633.       GetFieldWidth = 1100
  634.     Case dbCurrency
  635.       GetFieldWidth = 1800
  636.     Case dbSingle
  637.       GetFieldWidth = 1800
  638.     Case dbDouble
  639.       GetFieldWidth = 2200
  640.     Case dbDate
  641.       GetFieldWidth = 2000
  642.     Case dbText
  643.       GetFieldWidth = 3250
  644.     Case dbMemo
  645.       GetFieldWidth = 3250
  646.     Case Else
  647.       GetFieldWidth = 3250
  648.   End Select
  649. End Function
  650. Private Sub LoadFields()
  651.    Dim recTmp As Recordset
  652.    Dim nFldType As Integer
  653.    Dim i As Integer
  654.    On Error GoTo LoadFieldsErr
  655.    Set mrsFormRecordset = datDataCtl.Recordset
  656.    Set recTmp = mrsFormRecordset
  657.    mnNumFields = recTmp.Fields.Count
  658.    ReDim maFldArr(mnNumFields) As Object
  659.    lblFieldName(0).Visible = True
  660.    nFldType = recTmp.Fields(0).Type
  661.    If nFldType = dbBoolean Then
  662.      Set maFldArr(0) = chkFieldData(0)
  663.    ElseIf nFldType = dbLongBinary Then
  664.      If datDataCtl.Tag = "OLE" Then
  665.        Set maFldArr(0) = oleFieldData(0)
  666.      Else
  667.        Set maFldArr(0) = picFieldData(0)
  668.      End If
  669.    Else
  670.      Set maFldArr(0) = txtFieldData(0)
  671.    End If
  672.    maFldArr(0).Visible = True
  673.    maFldArr(0).Top = 0
  674.    maFldArr(0).Width = GetFieldWidth(nFldType)
  675.    If nFldType = dbText Then maFldArr(0).MaxLength = recTmp.Fields(0).Size
  676.    maFldArr(0).TabIndex = 0
  677.    On Error Resume Next
  678.    For i = 1 To recTmp.Fields.Count - 1
  679.      picFields.Height = picFields.Height + mnCTLARRAYHEIGHT
  680.      Load lblFieldName(i)
  681.      lblFieldName(i).Top = lblFieldName(i - 1).Top + mnCTLARRAYHEIGHT
  682.      lblFieldName(i).Visible = True
  683.      nFldType = recTmp.Fields(i).Type
  684.      If nFldType = dbBoolean Then
  685.        Load chkFieldData(i)
  686.        Set maFldArr(i) = chkFieldData(i)
  687.      ElseIf nFldType = dbLongBinary Then
  688.        If datDataCtl.Tag = "OLE" Then
  689.          Load oleFieldData(i)
  690.          Set maFldArr(i) = oleFieldData(i)
  691.        Else
  692.          Load picFieldData(i)
  693.          Set maFldArr(i) = picFieldData(i)
  694.        End If
  695.      Else
  696.        Load txtFieldData(i)
  697.        Set maFldArr(i) = txtFieldData(i)
  698.      End If
  699.      maFldArr(i).Top = maFldArr(i - 1).Top + mnCTLARRAYHEIGHT
  700.      maFldArr(i).Visible = True
  701.      maFldArr(i).Width = GetFieldWidth(nFldType)
  702.      maFldArr(i).TabIndex = i
  703.      If nFldType = dbText Then maFldArr(i).MaxLength = recTmp.Fields(i).Size
  704.    Next
  705.    On Error GoTo LoadFieldsErr
  706.    picFields.Top = picButtons.Top + picButtons.Height
  707.    mnFieldTop = picFields.Top
  708.    vsbScrollBar.Value = mnFieldTop
  709.    If i <= 10 Then
  710.      Height = i * mnCTLARRAYHEIGHT + 1500
  711.      vsbScrollBar.Visible = False
  712.    Else
  713.      Height = 4500
  714.      Width = Width + 260
  715.      vsbScrollBar.Visible = True
  716.      vsbScrollBar.Min = mnFieldTop
  717.      vsbScrollBar.Max = mnFieldTop - (i * mnCTLARRAYHEIGHT) + 3000
  718.    End If
  719.    For i = 0 To recTmp.Fields.Count - 1
  720.      lblFieldName(i).Caption = recTmp.Fields(i).Name & ":"
  721.    Next
  722.    On Error Resume Next   '
  723.    For i = 0 To recTmp.Fields.Count - 1
  724.      maFldArr(i).DataField = recTmp.Fields(i).Name
  725.    Next
  726.    Exit Sub
  727. LoadFieldsErr:
  728.    ShowErrMsg
  729.    Exit Sub
  730. End Sub
  731. Private Sub cmdRefresh_Click()
  732.   On Error GoTo RefErr
  733.   datDataCtl.Refresh
  734.   Exit Sub
  735. RefErr:
  736.   ShowErrMsg
  737. End Sub
  738. Private Sub SetRecNum()
  739.   On Error GoTo SRErr
  740.   Dim sCurrStat As String
  741.   Dim lCurrRec As Long
  742.   Dim bNoInd As Integer
  743.   mlNumRows = datDataCtl.Recordset.RecordCount
  744.   If datDataCtl.EditMode <> dbEditAdd Then
  745.     If datDataCtl.Recordset.BOF Then
  746.       sCurrStat = "(BOF)/" & mlNumRows
  747.     ElseIf datDataCtl.Recordset.EOF Then
  748.       sCurrStat = "(EOF)/" & mlNumRows
  749.     Else
  750.       '
  751.       If datDataCtl.Recordset.Type = dbOpenTable Then
  752.         If datDataCtl.Database(datDataCtl.RecordSource).Indexes.Count = 0 Then
  753.           bNoInd = True
  754.         End If
  755.       End If
  756.       '
  757.       'PercentPosition 
  758.       If bNoInd Then
  759.         sCurrStat = mlNumRows & MSG10
  760.       ElseIf (datDataCtl.Options And dbForwardOnly) = dbForwardOnly Then
  761.         sCurrStat = mlNumRows & MSG11
  762.       Else
  763.         lCurrRec = (mlNumRows * (datDataCtl.Recordset.PercentPosition * 0.01)) + 1
  764.         sCurrStat = lCurrRec & "/" & mlNumRows
  765.       End If
  766.     End If
  767.     If datDataCtl.Recordset.Updatable = False Then
  768.       sCurrStat = sCurrStat & MSG12
  769.       cmdAdd.Enabled = False
  770.       cmdCancelAdd.Enabled = False
  771.       cmdUpdate.Enabled = False
  772.       cmdDelete.Enabled = False
  773.     Else
  774.       cmdAdd.Enabled = True
  775.       cmdCancelAdd.Enabled = True
  776.       cmdUpdate.Enabled = True
  777.       cmdDelete.Enabled = True
  778.     End If
  779.     datDataCtl.Caption = sCurrStat
  780.   End If
  781.   If datDataCtl.EditMode <> dbEditAdd Then
  782.     cmdCancelAdd.Visible = False
  783.     cmdAdd.Visible = True
  784.   End If
  785.   Exit Sub
  786. SRErr:
  787.   If Err <> 3021 Then
  788.     ShowErrMsg
  789.   End If
  790.   Exit Sub
  791. End Sub
  792. Private Sub cmdUpdate_Click()
  793.   On Error GoTo UpdErr
  794.   Dim bAddFlag As Integer
  795.   Dim nDelay As Long
  796.   Dim nRetryCnt As Integer
  797.   bAddFlag = datDataCtl.EditMode
  798.   If datDataCtl.EditMode = dbEditAdd Then
  799.     If MsgBox(MSG4, mnMSGBOX_TYPE) = vbYes Then
  800.       Screen.MousePointer = vbHourglass
  801. RetryUpd1:
  802.       datDataCtl.UpdateRecord
  803.       mlNumRows = mlNumRows + 1
  804.     End If
  805.   Else
  806.     If MsgBox(MSG5, mnMSGBOX_TYPE) = vbYes Then
  807.       Screen.MousePointer = vbHourglass
  808. RetryUpd2:
  809.       datDataCtl.UpdateRecord
  810.     End If
  811.   End If
  812.   If bAddFlag = dbEditAdd Then
  813.     mrsFormRecordset.MoveLast
  814.   End If
  815.   DBEngine.Idle dbFreeLocks
  816.   Screen.MousePointer = vbDefault
  817.   Exit Sub
  818. UpdErr:
  819.   If Err = 3260 And nRetryCnt < gnMURetryCnt Then
  820.     nRetryCnt = nRetryCnt + 1
  821.     datDataCtl.Recordset.Bookmark = datDataCtl.Recordset.Bookmark   '
  822.     DBEngine.Idle dbFreeLocks
  823.     nDelay = Timer
  824.     '
  825.  gnMUDelay 
  826.     While Timer - nDelay < gnMUDelay
  827.       '
  828.     Wend
  829.     If datDataCtl.EditMode = dbEditAdd Then
  830.       Resume RetryUpd1
  831.     Else
  832.       Resume RetryUpd2
  833.     End If
  834.   Else
  835.     Screen.MousePointer = vbDefault
  836.     ShowErrMsg
  837.     Exit Sub
  838.   End If
  839. End Sub
  840. Private Sub ShowErrMsg()
  841.   MsgBox "
  842. " & Err & " " & Error
  843. End Sub
  844.