VBA question

briana banks

Member
Join Date
Jul 2005
Posts
242
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:
[HIGHLIGHT]
Public Sub InsertParentRecord()
[/HIGHLIGHT]
parent.CursorType = adOpenKeyset

parent.LockType = adLockOptimistic

parent.ActiveConnection = cn

parent.Open ("SELECT * FROM parent")

parent.AddNew

LocalDate = Date
LocalTime = Time
Date_Time = Date & " " & Time
parent.Fields("Date_Time").Value = Date_Time

parent.Fields("StartTime").Value = f1

parent.Fields("BatchNo").Value = f2

parent.Fields("Operator").Value = f3

parent.Update
parent.Close
[HIGHLIGHT]
End Sub

Public Sub InsertChildRecord()
[/HIGHLIGHT]
parent.CursorType = adOpenKeyset

parent.LockType = adLockOptimistic

parent.ActiveConnection = cn

parent.Open ("SELECT * FROM parent")
Child.CursorType = adOpenKeyset

Child.LockType = adLockOptimistic

Child.ActiveConnection = cn

Child.Open ("SELECT * FROM Child")

If parent.EOF = True Then 'MoveLast is not supported.
parent.MoveFirst
While parent.EOF = False
CurrentIndex = parent.Fields(0).Value
parent.MoveNext
Wend
End If

While parent.EOF = False
CurrentIndex = parent.Fields(0).Value
parent.MoveNext
Wend

Child.AddNew

Child.Fields("index").Value = CurrentIndex

f1 = StartHour & ":" & StartMin
f2 = StopHour & ":" & StopMin

Child.Fields("StartTime").Value = f1
Child.Fields("StopTime").Value = f2

If Step_no = 1 Then
[HIGHLIGHT]
'IT FAILS HERE BECAUSE PARENT TABLE IS IN EOF.
[/HIGHLIGHT]
parent.Fields("StartTime").Value = f1
End If
If Step_no = 3 Then
parent.Fields("StopTime").Value = f2
End If
parent.Update

Child.Update
Child.Close
parent.Close
[HIGHLIGHT]
End Sub
[/HIGHLIGHT]
 
Last edited:
briana banks said:
Hi All


If Step_no = 1 Then
[HIGHLIGHT]
'IT FAILS HERE BECAUSE PARENT TABLE IS IN EOF.
[/HIGHLIGHT]
parent.Fields("StartTime").Value = f1

Before the parent.fields() I don't see parent.AddNew() is that not needed?
 
It is failing, because in your search for the last 'index', your search condition terminates (a while) on Parent At EOF.

Before updating the parent record, you need to either scroll back through (movefirst/search) or just requery your Parent recordset looking for the found Index.
 

Similar Topics

Hi. So this is my first project with FT View SE coming from the WW world and it has been more than a little frustrating. Programming is not an...
Replies
0
Views
3,383
FTViewSE 7.0. I'm trying to set Object.Value = Object2.Value under certain conditions, but it doesn't seem to work. I have 2 objects on the...
Replies
1
Views
1,407
I may be barking up the wrong tree here. I am using Factory Talk View ME 7.00.00 What I am trying to do is to design a standard look and feel...
Replies
4
Views
7,341
I'm using RSView VBA to record the last parameter adjustments made for a given product in an MS Access data base. The Access table contains...
Replies
4
Views
2,338
I've seen a bunch of these while searching but none address what I'm trying to do. I'm just trying to learn how this works, I've done some...
Replies
1
Views
2,248
Back
Top Bottom