Hi All


I have 2 tables -parent table and child table.
first i call the parent function and after that i call
child function but IT FAILS BECAUSE PARENT TABLE IS IN EOF:

VB Code:
  1. Public Sub InsertParentRecord()
  2.  
  3. parent.CursorType = adOpenKeyset
  4.  
  5. parent.LockType = adLockOptimistic
  6.  
  7. parent.ActiveConnection = cn
  8.  
  9. parent.Open ("SELECT * FROM parent")
  10.  
  11. parent.AddNew
  12.  
  13. LocalDate = Date
  14. LocalTime = Time
  15. Date_Time = Date & " " & Time
  16. parent.Fields("Date_Time").Value = Date_Time
  17.  
  18. parent.Fields("StartTime").Value = f1
  19.  
  20. parent.Fields("BatchNo").Value = f2
  21.  
  22. parent.Fields("Operator").Value = f3
  23.  
  24. parent.Update
  25. parent.Close
  26.  
  27. End Sub
  28.  
  29. Public Sub InsertChildRecord()
  30.  
  31. parent.CursorType = adOpenKeyset
  32.  
  33. parent.LockType = adLockOptimistic
  34.  
  35. parent.ActiveConnection = cn
  36.  
  37. parent.Open ("SELECT * FROM parent")
  38. Child.CursorType = adOpenKeyset
  39.  
  40. Child.LockType = adLockOptimistic
  41.  
  42. Child.ActiveConnection = cn
  43.  
  44. Child.Open ("SELECT * FROM Child")
  45.  
  46. If parent.EOF = True Then 'MoveLast is not supported.
  47. parent.MoveFirst
  48. While parent.EOF = False
  49. CurrentIndex = parent.Fields(0).Value
  50. parent.MoveNext
  51. Wend
  52. End If
  53.  
  54. While parent.EOF = False
  55. CurrentIndex = parent.Fields(0).Value
  56. parent.MoveNext
  57. Wend
  58.  
  59. Child.AddNew
  60.  
  61. Child.Fields("index").Value = CurrentIndex
  62.  
  63. f1 = StartHour & ":" & StartMin
  64. f2 = StopHour & ":" & StopMin
  65.  
  66. Child.Fields("StartTime").Value = f1
  67. Child.Fields("StopTime").Value = f2
  68.  
  69. If Step_no = 1 Then
  70.  
  71. 'IT FAILS HERE BECAUSE PARENT TABLE IS IN EOF.
  72.  
  73. parent.Fields("StartTime").Value = f1
  74. End If
  75. If Step_no = 3 Then
  76. parent.Fields("StopTime").Value = f2
  77. End If
  78. parent.Update
  79.  
  80. Child.Update
  81. Child.Close
  82. parent.Close
  83.  
  84. End Sub