home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 6 Unleashed…sional Reference Edition) / Visual_Basic_6_Unleashed_Professional_Reference_Edition_Sams_1999.iso / Source / CHAP16 / rsclsDataObjClass.cls < prev   
Encoding:
Visual Basic class definition  |  1998-06-11  |  25.7 KB  |  855 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 1  'vbDataSource
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "rsclsDataObjClass"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "WizardYN" ,"Yes"
  15. Attribute VB_Ext_KEY = "VBProjectName" ,"Project1"
  16. Attribute VB_Ext_KEY = "DEDesignerName" ,"DataEnvironment1"
  17. Attribute VB_Ext_KEY = "ConnectionName" ,"Connection1"
  18. Attribute VB_Ext_KEY = "CommandName" ,"OrderInfo"
  19. Attribute VB_Ext_KEY = "ClassRootName" ,"DataObjClass"
  20. Attribute VB_Ext_KEY = "ClassType" ,"Data Class"
  21. Attribute VB_Ext_KEY = "FKCommand1" ,"Customers"
  22. Attribute VB_Ext_KEY = "FKCommand1_SELECTFIELDNAME1" ,"customerid"
  23. Attribute VB_Ext_KEY = "FKCommand1_SELECTCOMMANDNAME1" ,"OrderInfo"
  24. Attribute VB_Ext_KEY = "FKCommand1_FKFIELDNAME1" ,"customerid"
  25. Attribute VB_Ext_KEY = "FKCommand1_FKCOMMANDNAME1" ,"Customers"
  26. Attribute VB_Ext_KEY = "FKCommand1_FKDESCRIPTOR1" ,"CompanyName"
  27. Attribute VB_Ext_KEY = "FKCommand1_FKNULLABLE1" ,"Yes"
  28. Attribute VB_Ext_KEY = "FKCommand1_FKPKCount" ," 1"
  29. Attribute VB_Ext_KEY = "SelectCommandName" ,"OrderInfo"
  30. Attribute VB_Ext_KEY = "FieldNullableOrderID" ,"Yes"
  31. Attribute VB_Ext_KEY = "FieldPKOrderID" ,"No"
  32. Attribute VB_Ext_KEY = "FieldNullableCustomerID" ,"Yes"
  33. Attribute VB_Ext_KEY = "FieldPKCustomerID" ,"No"
  34. Attribute VB_Ext_KEY = "FieldNullableOrderDate" ,"Yes"
  35. Attribute VB_Ext_KEY = "FieldPKOrderDate" ,"No"
  36. Attribute VB_Ext_KEY = "FieldNullableProductID" ,"Yes"
  37. Attribute VB_Ext_KEY = "FieldPKProductID" ,"No"
  38. Attribute VB_Ext_KEY = "FieldNullableUnitPrice" ,"Yes"
  39. Attribute VB_Ext_KEY = "FieldPKUnitPrice" ,"No"
  40. Attribute VB_Ext_KEY = "FieldNullableQuantity" ,"Yes"
  41. Attribute VB_Ext_KEY = "FieldPKQuantity" ,"No"
  42. Attribute VB_Ext_KEY = "NumFKCommands" ,"1"
  43. Attribute VB_Ext_KEY = "NumInterfaces" ,"1"
  44. Attribute VB_Ext_KEY = "UseSelectCommand" ,"False"
  45. '=============================================================
  46. 'Name: rsclsDataObjClass (a RecordSet class)
  47. '
  48. 'Author: Microsoft Data Object Wizard
  49. '
  50. 'Date: 06/11/1998 18:39
  51. '
  52. 'Description: Contains RecordSet class used as a DataSource class
  53.     'for a UserControl object.
  54. '
  55. 'Comment: A new RecordSet class is created from the main 'Select' RecordSet class.
  56.     'This RecordSet class is not connected to the database to allow for
  57.     '(1) separate stored procedures for updates, inserts and deletes
  58.      'and (2) control of update timing.
  59. '=============================================================
  60.  
  61. Public SaveMode As EnumSaveMode 'Specifies either the Immediate or Batch mode Save property for the ResultSet class.
  62.  
  63. 'The Data Environment object contains all the data access commands.
  64. Private de1 As New DataEnvironment1
  65.  
  66. 'Create a new RecordSet class to hold the Foreign Key attributes,
  67. '    unless there are no Foreign Key attributes, then the Data Environment RecordSet class will be used.
  68. Private WithEvents rs As Recordset
  69. Attribute rs.VB_VarHelpID = -1
  70.  
  71. 'Variant to store system generated Primary Key values.
  72. Private vPKValues() As Variant
  73.  
  74. 'Set the flag when record sets have been initialized.
  75. Private mbDataInitialized As Boolean
  76. 'Flag to prohibit running the WillChangeRecord event.
  77. Private mbAddingRecord As Boolean
  78. 'Flag to prohibit running the WillChangeRecord event when RecordSet class moves after the Delete method runs.
  79. Private mbDeleteInProgress As Boolean
  80.  
  81. Private bInitComplete As Boolean 'Boolean flag is set when GetDataMember event is complete.
  82. 'This event is run when the RecordSet Move method is complete.
  83. Public Event rsMoveComplete()
  84. 'This event is run when the RecordSet Delete method is complete.
  85. Public Event DeleteRecordComplete()
  86. 'This event is run when the rsUpdate method is complete.
  87. Public Event rsUpdateEvent(vFieldName As Variant)
  88. 'This event is run for certain class errors.
  89. Public Event ClassError(sProcedureName As String, oErr As ErrObject)
  90.  
  91. ' rsclsDataObjClass Foreign Key RecordSet classes
  92. Public rsCustomers As ADODB.Recordset
  93.  
  94. 'Foreign Key Parameter properties for the RecordSet classes.
  95.  
  96. 'The external interface Get and Let properties.
  97. Public Property Get OrderID() As Variant
  98.     OrderID = rs("OrderID")
  99. End Property
  100. Public Property Let OrderID(vOrderID As Variant)
  101.     If IsNull(vOrderID) Then
  102.         rs("OrderID") = Null
  103.     Else
  104.         rs("OrderID") = CLng(vOrderID)
  105.     End If
  106. End Property
  107.  
  108. Public Property Get customerid() As Variant
  109.     customerid = rs("CustomerID")
  110. End Property
  111. Public Property Let customerid(vCustomerID As Variant)
  112.     If IsNull(vCustomerID) Then
  113.         rs("CustomerID") = Null
  114.     Else
  115.         rs("CustomerID") = CStr(vCustomerID)
  116.     End If
  117. End Property
  118.  
  119. Public Property Get OrderDate() As Variant
  120.     OrderDate = rs("OrderDate")
  121. End Property
  122. Public Property Let OrderDate(vOrderDate As Variant)
  123.     If IsNull(vOrderDate) Then
  124.         rs("OrderDate") = Null
  125.     Else
  126.         rs("OrderDate") = CDate(vOrderDate)
  127.     End If
  128. End Property
  129.  
  130. Public Property Get ProductID() As Variant
  131.     ProductID = rs("ProductID")
  132. End Property
  133. Public Property Let ProductID(vProductID As Variant)
  134.     If IsNull(vProductID) Then
  135.         rs("ProductID") = Null
  136.     Else
  137.         rs("ProductID") = CLng(vProductID)
  138.     End If
  139. End Property
  140.  
  141. Public Property Get UnitPrice() As Variant
  142.     UnitPrice = rs("UnitPrice")
  143. End Property
  144. Public Property Let UnitPrice(vUnitPrice As Variant)
  145.     If IsNull(vUnitPrice) Then
  146.         rs("UnitPrice") = Null
  147.     Else
  148.         rs("UnitPrice") = CCur(vUnitPrice)
  149.     End If
  150. End Property
  151.  
  152. Public Property Get Quantity() As Variant
  153.     Quantity = rs("Quantity")
  154. End Property
  155. Public Property Let Quantity(vQuantity As Variant)
  156.     If IsNull(vQuantity) Then
  157.         rs("Quantity") = Null
  158.     Else
  159.         rs("Quantity") = CInt(vQuantity)
  160.     End If
  161. End Property
  162.  
  163. 'The RecordSet Beginnig Of File status.
  164. Public Property Get BOF() As Boolean
  165.     BOF = rs.BOF
  166. End Property
  167.  
  168. 'The RecordSet End Of File status.
  169. Public Property Get EOF() As Boolean
  170.     EOF = rs.EOF
  171. End Property
  172.  
  173. 'The RecordSet AbsolutePosition property.
  174. Public Property Let AbsolutePosition(lAbsolutePosition As Long)
  175.     rs.AbsolutePosition = lAbsolutePosition
  176. End Property
  177.  
  178. Public Property Get AbsolutePosition() As Long
  179.     AbsolutePosition = rs.AbsolutePosition
  180. End Property
  181.  
  182. 'The Foreign Key Descriptor properties.
  183. Public Property Get CustomersCompanyName() As Variant
  184.     CustomersCompanyName = rs("CustomersCompanyName")
  185. End Property
  186. Public Property Let CustomersCompanyName(vCompanyName As Variant)
  187.     rs("CustomersCompanyName") = vCompanyName
  188. End Property
  189.  
  190. Private Sub Class_GetDataMember(DataMember As String, Data As Object)
  191. '=============================================================
  192. 'Name: Class_GetDataMember
  193. '
  194. 'Author: Microsoft Data Object Wizard
  195. '
  196. 'Date: 06/11/1998 18:39
  197. '
  198. 'Description: Creates and allows selection of RecordSet classes.
  199. '
  200. 'Comment: A new RecordSet is created from the 'Select' RecordSet class.
  201. '   Foreign Key Descriptor columns are added to this RecordSet class and
  202. '   updated with the Foreign Key Data Environment commands mapped to the Select Foreign Key values.
  203. '=============================================================
  204.  
  205. Dim i As Integer
  206. Dim sLastFieldName As String
  207. Dim sName() As Variant
  208. Dim vValue() As Variant
  209. Dim sNames As Variant
  210. Dim vValues As Variant
  211. Dim oField As Field
  212.  
  213. On Error GoTo errMSDOG_GDM:
  214.  
  215. bInitComplete = False
  216.  
  217. 'Choose the RecordSet class based on the DataMember parameter.
  218. Select Case LCase(DataMember)
  219.     Case "orderinfo":
  220.         'Skip initialization if RecordSet class already exists.
  221.         If Not mbDataInitialized Then
  222.             de1.rsOrderInfo.DataMember = ""
  223.  
  224.             If SaveMode = adImmediate Then
  225.                 de1.rsOrderInfo.LockType = adLockOptimistic
  226.             Else
  227.                 de1.rsOrderInfo.LockType = adLockBatchOptimistic
  228.             End If
  229.  
  230.             de1.OrderInfo
  231.             'Disconnect the RecordSet class to allow (1) stored procedure access
  232.             '  and (2) control over database update timing.
  233.             Set de1.rsOrderInfo.ActiveConnection = Nothing
  234.  
  235.             'Data object has been initiallized.
  236.             mbDataInitialized = True
  237.  
  238.             'Execute the Foreign Key command.
  239.             de1.Customers
  240.             'If there are no Foreign Keys records, exit with a ClassError event.
  241.             If de1.rsCustomers.RecordCount < 1 Then
  242.                 Err.Clear
  243.                 Set Data = Nothing
  244.                 RaiseEvent ClassError("GetDataMember-No Customers records.", Err)
  245.                 Exit Sub
  246.             End If
  247.  
  248.             'Set the Public property to expose the Foreign Key RecordSet class.
  249.             Set rsCustomers = de1.rsCustomers
  250.             'Disconnect the Foreign Key RecordSet class from the DataSource class.
  251.             Set de1.rsCustomers.ActiveConnection = Nothing
  252.  
  253.             'Instantiate the new RecordSet class.
  254.             Set rs = New ADODB.Recordset
  255.  
  256.             'Set the CursorType property of the RecordSet class.
  257.             rs.CursorType = adOpenStatic
  258.             'Set the LockType property of the RecordSet class.
  259.             If SaveMode = adImmediate Then
  260.                 rs.LockType = adLockOptimistic
  261.             Else
  262.                 rs.LockType = adLockBatchOptimistic
  263.             End If
  264.  
  265.             i = -1
  266.             sLastFieldName = ""
  267.  
  268.             'Loop through each field in the Select command,
  269.     'adding the field to the created RecordSet class.
  270.     'If the field is the last field in an Foreign Key command,
  271.     'then add the Foreign Key Descriptor field.
  272.             For Each oField In de1.rsOrderInfo.Fields
  273.                 'Is the Select field the last one in an Foreign Key command?
  274.                 Select Case LCase(sLastFieldName)
  275.                     Case "customerid"
  276.                         i = i + 1
  277.                         ReDim Preserve sName(i)
  278.                         sName(i) = "CustomersCompanyName"
  279.                         'Add the Foreign Key Descriptor field to the RecordSet class.
  280.                         rs.Fields.Append "CustomersCompanyName", _
  281.                             de1.rsCustomers.Fields("CompanyName").Type, _
  282.                             de1.rsCustomers.Fields("CompanyName").DefinedSize, _
  283.                             de1.rsCustomers.Fields("CompanyName").Attributes
  284.                 End Select
  285.  
  286.                 i = i + 1
  287.  
  288.                 ReDim Preserve sName(i)
  289.  
  290.                 sName(i) = oField.Name
  291.  
  292.                 'Add the Select field to the RecordSet class.
  293.                 rs.Fields.Append oField.Name, oField.Type, oField.DefinedSize, oField.Attributes
  294.  
  295.                 'Set the Precision property to the same as in the original RecordSet class.
  296.                 rs.Fields(i).Precision = oField.Precision
  297.                 'Set the NumericScale property to the same as in the original RecordSet class.
  298.                 rs.Fields(i).NumericScale = oField.NumericScale
  299.  
  300.                 sLastFieldName = sName(i)
  301.             Next oField
  302.  
  303.             'Open the newly created RecordSet class.
  304.             rs.Open
  305.  
  306.             'Move to the first record in the RecordSet class.
  307.             If de1.rsOrderInfo.RecordCount > 0 Then
  308.                 de1.rsOrderInfo.MoveFirst
  309.             End If
  310.  
  311.             'Loop through each record in the RecordSet class.
  312.     'If the Select field is a Foreign Key Descriptor field, look up it's value
  313.     'in the Foreign Key command Descriptor field, then update the
  314.     'Select Foreign Key Descriptor field with that value.
  315.             While Not de1.rsOrderInfo.EOF
  316.                 i = -1
  317.                 sLastFieldName = ""
  318.                 For Each oField In de1.rsOrderInfo.Fields
  319.                     'Is the field a Foreign Key Descriptor field?
  320.                     Select Case LCase(sLastFieldName)
  321.                         Case "customerid"
  322.                             i = i + 1
  323.                             ReDim Preserve vValue(i)
  324.                             vValue(i) = Null
  325.                             de1.rsCustomers.MoveFirst
  326.  
  327.                             'Loop through the Foreign Key RecordSet class until the Select value is found.
  328.                             Do While Not de1.rsCustomers.EOF
  329.                             'If the Select Foreign Key values equal the Foreign Key command Primary Key values, update the Foreign Key Descriptor field.
  330.                                 If _
  331.                                 de1.rsCustomers("customerid") = de1.rsOrderInfo("customerid") Then
  332.                                     'Load the vValue Array element with the Foreign Key Descriptor value.
  333.                                     vValue(i) = de1.rsCustomers("CompanyName")
  334.  
  335.                                     Exit Do
  336.                                 End If
  337.  
  338.                                 'Move to the next record with a Foreign Key attribute.
  339.                                 de1.rsCustomers.MoveNext
  340.                             Loop
  341.  
  342.                             'If the value is null, then set the Foreign Key Descriptor Array element value to '(None).
  343.                             If IsNull(vValue(i)) Then
  344.                                 vValue(i) = "(None)"
  345.                             End If
  346.                     End Select
  347.  
  348.                     i = i + 1
  349.  
  350.                     ReDim Preserve vValue(i)
  351.  
  352.                     'Set the Array element equal to the value in the Select field.
  353.                     vValue(i) = de1.rsOrderInfo(oField.Name).Value
  354.  
  355.                     sLastFieldName = oField.Name
  356.                 Next oField
  357.  
  358.                 'To add a record to a RecordSet class two arrays of variants are required,
  359.     '(1) an array of field names and (2) an array of corresponding values.
  360.                 sNames = sName()
  361.                 vValues = vValue()
  362.  
  363.                 'Add the record to the created RecordSet class.
  364.                 rs.AddNew sNames, vValues
  365.  
  366.                 'Move to the next record in the Select RecordSet class.
  367.                 de1.rsOrderInfo.MoveNext
  368.             Wend
  369.  
  370.             'Move to the first record in the created RecordSet class.
  371.             rs.MoveFirst
  372.         End If
  373.  
  374.         'Update all the RecordSet class row status to 'unmodified'.
  375.         rs.UpdateBatch
  376.  
  377.         'ReDimension the array to hold system generated Primary Key values.
  378.         ReDim vPKValues(2, 0)
  379.  
  380.         'Set the Data object to return the Select RecordSet class to the calling procedure.
  381.         Set Data = rs
  382.  
  383.     Case "customers"
  384.         'Set the Data object to return the Foreign Key RecordSet class to the calling procedure.
  385.         Set Data = de1.rsCustomers
  386. End Select
  387.  
  388. bInitComplete = True
  389.  
  390. Exit Sub
  391. errMSDOG_GDM:
  392.     RaiseEvent ClassError("GetDataMember", Err)
  393. End Sub
  394.  
  395. Private Sub Class_Initialize()
  396. '=============================================================
  397. 'Name: Class_Initialize
  398. '
  399. 'Author: Microsoft Data Object Wizard
  400. '
  401. 'Date: 06/11/1998 18:39
  402. '
  403. 'Description: Standard Class object Initialize event.
  404. '
  405. 'Comment:
  406. '=============================================================
  407.  
  408.     'Reset the Initialization variable.
  409.     mbDataInitialized = False
  410. End Sub
  411.  
  412. Private Sub Class_Terminate()
  413. '=============================================================
  414. 'Name: Class_Terminate
  415. '
  416. 'Author: Microsoft Data Object Wizard
  417. '
  418. 'Date: 06/11/1998 18:39
  419. '
  420. 'Description: Closes Data Environment connections and uninitializes objects
  421. '
  422. 'Comment:
  423. '=============================================================
  424.  
  425.     'Close the Data Environment connection
  426.     de1.Connection1.Close
  427.     'Release the Data Environment and RecordSet objects
  428.     Set de1 = Nothing
  429.     Set rs = Nothing
  430. End Sub
  431.  
  432.  
  433. Private Sub RS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _
  434.         ByVal pError As ADODB.Error, _
  435.         adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
  436. '=============================================================
  437. 'Name: RS_MoveComplete
  438. '
  439. 'Author: Microsoft Data Object Wizard
  440. '
  441. 'Date: 06/11/1998 18:39
  442. '
  443. 'Description: Standard RecordSet MoveComplete event.
  444. '
  445. 'Comment:
  446. '=============================================================
  447.  
  448.     'Exit the subroutine if the Beginning Of File property is true
  449.     If rs.BOF Then
  450.         Exit Sub
  451.     End If
  452.  
  453.     'Exit the subroutine if the End Of File Property is true
  454.     If rs.EOF Then
  455.         Exit Sub
  456.     End If
  457.  
  458.     'Raise the rsMoveComplete event
  459.  
  460.     RaiseEvent rsMoveComplete
  461.  
  462. End Sub
  463.  
  464. Public Sub Move(lRows As Long)
  465. '=============================================================
  466. 'Name: Move
  467. '
  468. 'Author: Microsoft Data Object Wizard
  469. '
  470. 'Date: 06/11/1998 18:39
  471. '
  472. 'Description: Move the RecordSet n number of Rows.
  473. '
  474. 'Comment:
  475. '=============================================================
  476.  
  477.     On Error GoTo errMove:
  478.  
  479.     rs.Move lRows
  480.  
  481. Exit Sub
  482. errMove:
  483. End Sub
  484.  
  485. Public Sub MoveNext()
  486. '=============================================================
  487. 'Name: MoveNext
  488. '
  489. 'Author: Microsoft Data Object Wizard
  490. '
  491. 'Date: 06/11/1998 18:39
  492. '
  493. 'Description: Move to next record.
  494. '
  495. 'Comment:
  496. '=============================================================
  497.  
  498.     If (rs.RecordCount > 0) And (Not rs.EOF) Then
  499.         rs.MoveNext
  500.     End If
  501. End Sub
  502.  
  503. Public Sub MoveFirst()
  504. '=============================================================
  505. 'Name: MoveFirst
  506. '
  507. 'Author: Microsoft Data Object Wizard
  508. '
  509. 'Date: 06/11/1998 18:39
  510. '
  511. 'Description: Move to first record.
  512. '
  513. 'Comment:
  514. '=============================================================
  515.  
  516.     If rs.RecordCount > 0 Then
  517.         rs.MoveFirst
  518.     End If
  519. End Sub
  520.  
  521. Public Sub MovePrevious()
  522. '=============================================================
  523. 'Name: MovePrevious
  524. '
  525. 'Author: Microsoft Data Object Wizard
  526. '
  527. 'Date: 06/11/1998 18:39
  528. '
  529. 'Description: Move to previous record.
  530. '
  531. 'Comment:
  532. '=============================================================
  533.  
  534.     If (rs.RecordCount > 0) And (Not rs.BOF) Then
  535.         rs.MovePrevious
  536.     End If
  537. End Sub
  538.  
  539. Public Sub MoveLast()
  540. '=============================================================
  541. 'Name: MoveLast
  542. '
  543. 'Author: Microsoft Data Object Wizard
  544. '
  545. 'Date: 06/11/1998 18:39
  546. '
  547. 'Description: Move to last record.
  548. '
  549. 'Comment:
  550. '=============================================================
  551.  
  552.     If rs.RecordCount > 0 Then
  553.         rs.MoveLast
  554.     End If
  555. End Sub
  556.  
  557.  
  558. Public Function ValidateData() As Boolean
  559. '=============================================================
  560. 'Name: ValidateData
  561. '
  562. 'Author: Microsoft Data Object Wizard
  563. '
  564. 'Date: 06/11/1998 18:39
  565. '
  566. 'Description: This Function validates the RecordSet class data.
  567. '
  568. 'Comment:
  569. '=============================================================
  570.  
  571.     Dim i As Long
  572.  
  573.     ValidateData = False
  574.  
  575.     For i = 0 To rs.Fields.Count - 1
  576.         Select Case LCase(rs.Fields(i).Name)
  577.             Case "orderid", "customerid", "orderdate", "productid", "unitprice", "quantity"
  578.                 If IsEmpty(rs(i)) And Not rs(i).Type = adBoolean Then
  579.                     MsgBox rs(i).Name & " error."
  580.                     Exit Function
  581.                 End If
  582.         End Select
  583.     Next i
  584.  
  585.     'Verify the integer field contains a valid value.
  586.     If Not IsNull(rs("OrderID")) Then
  587.         If Not IsNumeric(rs("OrderID")) _
  588.             And InStr(rs("OrderID"), ".") = 0 Then
  589.             MsgBox "The field ' OrderID ' does not contain a valid number."
  590.         Exit Function
  591.         End If
  592.     End If
  593.  
  594.     'Verify the text field contains text.
  595.     If Not IsNull(rs("CustomerID")) Then
  596.         If Len(Trim(rs("CustomerID"))) = 0 Then
  597.             MsgBox "The field ' CustomerID ' does not contain valid text."
  598.             Exit Function
  599.         End If
  600.     End If
  601.  
  602.     'Verify the date field contains a valid date.
  603.     If Not IsNull(rs("OrderDate")) Then
  604.         If Not IsDate(rs("OrderDate")) Then
  605.             MsgBox "The field ' OrderDate ' does not contain a valid date."
  606.             Exit Function
  607.         End If
  608.     End If
  609.  
  610.     'Verify the integer field contains a valid value.
  611.     If Not IsNull(rs("ProductID")) Then
  612.         If Not IsNumeric(rs("ProductID")) _
  613.             And InStr(rs("ProductID"), ".") = 0 Then
  614.             MsgBox "The field ' ProductID ' does not contain a valid number."
  615.         Exit Function
  616.         End If
  617.     End If
  618.  
  619.     'Verify the decimal field contains a valid value.
  620.     If Not IsNull(rs("UnitPrice")) Then
  621.         If Not IsNumeric(rs("UnitPrice")) Then
  622.             MsgBox "The field ' UnitPrice ' does not contain a valid numeric value."
  623.             Exit Function
  624.         End If
  625.     End If
  626.  
  627.     'Verify the integer field contains a valid value.
  628.     If Not IsNull(rs("Quantity")) Then
  629.         If Not IsNumeric(rs("Quantity")) _
  630.             And InStr(rs("Quantity"), ".") = 0 Then
  631.             MsgBox "The field ' Quantity ' does not contain a valid number."
  632.         Exit Function
  633.         End If
  634.     End If
  635.  
  636.  
  637.     ValidateData = True
  638.  
  639. End Function
  640.  
  641. Public Sub UpdateBatch()
  642. '=============================================================
  643. 'Name: Update Batch
  644. '
  645. 'Author: Microsoft Data Object Wizard
  646. '
  647. 'Date: 06/11/1998 18:39
  648. '
  649. 'Description: Saves all modified records.
  650. '
  651. 'Comment:
  652. '=============================================================
  653.  
  654.     On Error GoTo errUpdateBatch:
  655.  
  656.  
  657.     rs.UpdateBatch
  658.  
  659.     Exit Sub
  660. errUpdateBatch:
  661.     RaiseEvent ClassError("UpdateBatch", Err)
  662. End Sub
  663.  
  664.  
  665. Public Sub Update()
  666. '=============================================================
  667. 'Name: Update
  668. '
  669. 'Author: Microsoft Data Object Wizard
  670. '
  671. 'Date: 06/11/1998 18:39
  672. '
  673. 'Description: Saves a single record of the record set.
  674. '
  675. 'Comment:
  676. '=============================================================
  677.  
  678.     On Error GoTo errUpdate:
  679.  
  680.     rs.UpdateBatch adAffectCurrent
  681.  
  682.     Exit Sub
  683.  
  684. errUpdate:
  685.     RaiseEvent ClassError("Update", Err)
  686. End Sub
  687.  
  688.  
  689. Public Sub AddRecord()
  690. '=============================================================
  691. 'Name: AddRecord
  692. '
  693. 'Author: Microsoft Data Object Wizard
  694. '
  695. 'Date: 06/11/1998 18:39
  696. '
  697. 'Description: Adds a blank record to the RecordSet class.
  698. '
  699. 'Comment: .
  700. '=============================================================
  701.  
  702.     mbAddingRecord = True
  703.  
  704.     With rs
  705.         .AddNew
  706.         .Update
  707.     End With
  708.  
  709.     mbAddingRecord = False
  710.  
  711.     rs.MoveLast
  712.  
  713. End Sub
  714.  
  715.  
  716. Private Sub UpdateCustomersCompanyName()
  717. '=============================================================
  718. 'Name: UpdateCustomersCompanyName
  719. '
  720. 'Author: Microsoft Data Object Wizard
  721. '
  722. 'Date: 06/11/1998 18:39
  723. '
  724. 'Description: Updates Foreign Key Descriptor field.
  725. '
  726. 'Comment:
  727. '=============================================================
  728.  
  729.     de1.rsCustomers.MoveFirst
  730.  
  731.     rs("CustomersCompanyName") = "(None)"
  732.     CustomersCompanyName = "(None)"
  733.  
  734.     While Not de1.rsCustomers.EOF
  735.         If _
  736.             de1.rsCustomers("customerid") = rs("customerid") Then
  737.                 rs("CustomersCompanyName") = CStr(de1.rsCustomers("CompanyName"))
  738.                 CustomersCompanyName = CStr(de1.rsCustomers("CompanyName"))
  739.         End If
  740.  
  741.         de1.rsCustomers.MoveNext
  742.     Wend
  743. End Sub
  744.  
  745. Public Sub rsUpdate(vFieldName As Variant)
  746. '=============================================================
  747. 'Name: rsUpdate
  748. '
  749. 'Author: Microsoft Data Object Wizard
  750. '
  751. 'Date: 06/11/1998 18:39
  752. '
  753. 'Description: Updates Foreign Key Descriptors and raises rsUpdate event
  754. '
  755. 'Comment:
  756. '=============================================================
  757.  
  758.     UpdateCustomersCompanyName
  759.  
  760.     RaiseEvent rsUpdateEvent(vFieldName)
  761. End Sub
  762.  
  763. Public Sub Delete()
  764. '=============================================================
  765. 'Name: Delete
  766. '
  767. 'Author: Microsoft Data Object Wizard
  768. '
  769. 'Date: 06/11/1998 18:39
  770. '
  771. 'Description: This subroutine deletes a single record.
  772. '
  773. 'Comment:
  774. '=============================================================
  775.  
  776.     On Error GoTo errDelete
  777.  
  778.     mbDeleteInProgress = True
  779.  
  780.     On Error GoTo 0
  781.  
  782.     Me.MovePrevious
  783.  
  784.     mbDeleteInProgress = False
  785.  
  786.     Exit Sub
  787.  
  788. errDelete:
  789.     RaiseEvent ClassError("Delete", Err)
  790. End Sub
  791.  
  792.  
  793. Private Sub rs_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
  794. '=============================================================
  795. 'Name: rs_WillChangeRecord
  796. '
  797. 'Author: Microsoft Data Object Wizard
  798. '
  799. 'Date: 06/11/1998 18:39
  800. '
  801. 'Description: Runs stored procedures to save record.
  802. '
  803. 'Comment:
  804. '=============================================================
  805.  
  806. On Error GoTo errWillChangeRecord
  807.     If bInitComplete And (adReason <> adRsnFirstChange) And (adReason <> adRsnUndoAddNew) And Not mbAddingRecord Then
  808.         If IsEmpty(rs(0).OriginalValue) Then
  809.         Else
  810.             Select Case adReason
  811.                 Case adRsnUpdate
  812.                     If Not mbDeleteInProgress Then
  813.                     End If
  814.                 Case adRsnAddNew
  815.                 Case adRsnDelete
  816.                     mbDeleteInProgress = True
  817.             End Select
  818.         End If
  819.     End If
  820.  
  821.     Exit Sub
  822.  
  823. errWillChangeRecord:
  824.  
  825. End Sub
  826.  
  827.  
  828. Private Function GetPKValue(vBookMark As Variant, sColName As String) As Variant
  829. '=============================================================
  830. 'Name: GetPKValue
  831. '
  832. 'Author: Microsoft Data Object Wizard
  833. '
  834. 'Date: 06/11/1998 18:39
  835. '
  836. 'Description: Looks up newly inserted system gen'd PK values.
  837. '
  838. 'Comment:
  839. '=============================================================
  840.  
  841.     Dim i As Integer
  842.  
  843.     GetPKValue = rs(sColName)
  844.  
  845.     For i = 1 To UBound(vPKValues, 2)
  846.         If vPKValues(0, i) = vBookMark And LCase(vPKValues(1, i)) = LCase(sColName) Then
  847.             GetPKValue = vPKValues(2, i)
  848.             Exit Function
  849.         End If
  850.     Next i
  851. End Function
  852.  
  853.  
  854.  
  855.