Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update child records

Status
Not open for further replies.

dougscrm

Programmer
Oct 19, 2002
15
0
0
US
I've used Set Relation to relate a parent to child and I'm attempting to update all child records with a value from the parent record. I can get it to update the first of the child records for each parent but if there is more than one child record those don't get updated.

Here's the code

Code:
GO TOP 
m.tmkey=contact1.recordid
DO WHILE NOT EOF()
  REPLACE contact2.recordid WITH m.tmkey 
  SKIP + 1
  m.tmkey=contact1.recordid
ENDDO

I've tried lots of variations on the REPLACE line using FOR, WHILE etc to no avail
 
I think with FP you can use SQL type statements maybe if you went that route instead. When you read a parent record to a seperate update to all child records.

Or instead do a loop within a loop

Go Top
Do While EOF
Get all child records = parent

Do While Eof
update child
skip
EndDo

Skip
EndDo

I'd use proper syntax only that it is a long time since I used Foxpro
 
Created a test parent and child database and found that my code works there - The problem was very strange pk-fk combination with case sensitive and upper ascii characters included. The primary key is a substring of the foreign key (foreign key is longer so that it can double as a record identifier for each child record. The application is Telemagic. If anyone has any experience porting Telemagic data to another system that is case insensitive (SQL and Access) please let me know how you dealt with the keys
 
I don't know Telemagic and I'm not 100% clear on your issue with case sensitivity.

First, Foxpro is case sensitive since ASC("A") does not equal ASC("a"). If you are having problems with case, then you might want to work with the UPPER() or LOWER(), etc. commands so as to make the values appear to be the equal.

Also you are not correct when you say: "another system that is case insensitive (SQL and Access)" since these languages/systems are also case sensitive.

Second, remember that you cannot change the value of the child field on which the relation is set without possibly messing up the table relationship.

Regardless of that, your code above has a number of problems with it if you want to write to many child records for each parent record.

Give us more info on how your table relations are created and if the relation uses the RecordID fields. With that we can better help you correct your code.

Having done a wide variety of data conversions, let me know if you need additional help.

Good Luck,
JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top