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