Results 1 to 5 of 5

Thread: VBA question

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    6

    VBA question

    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

  2. #2
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Re: VBA question

    Quote Originally Posted by briana_banks
    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
    what is your question and it is Access or what?
    did you insert to parent table or not if not how can the child table get reference of the parent table.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    6

    Re: VBA question

    Hi

    Using Access...
    insert to parent table or not if not how can the child table get reference of
    the parent table
    Please take a look at the code
    VB Code:
    1. Child.AddNew
    2. Child.Fields("index").Value = CurrentIndex

    Please take a look at the code .I marked the place where it fails.
    Last edited by briana_banks; Nov 8th, 2005 at 05:56 AM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VBA question

    Moved to Office Development.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    6

    Question Re: VBA question

    ??

    I did it already.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width