Recref/fieldref Loop

Belias
Member Posts: 2,998
CLEAR(RecRef); CLEAR(FieldRef); CLEAR(TBField); RecRef.OPEN(INTTableNo); RecRefHT.OPEN(INTHistTableNo); TBField.SETRANGE(TableNo,INTHistTableNo); IF RecRef.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT RecRefHT.INIT; TFFirstLoop := TRUE; IF TBField.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT FieldRef := RecRef.FIELD(TBField."No."); FieldRefHT := RecRefHT.FIELD(TBField."No."); IF NOT CONFIRM ('a' + FORMAT(FieldRefHT.VALUE) + 'b' + FORMAT(FieldRef.VALUE)) THEN ERROR('a'); FieldRefHT.VALUE := FieldRef.VALUE; TFFirstLoop := FALSE; IF TFFirstLoop THEN BEGIN RecRefHT.INSERT; END ELSE RecRefHT.MODIFY; UNTIL TBField.NEXT = 0; END; UNTIL RecRef.NEXT = 0; END;
it keeps giving me this error:
Identification fields and values:
List Type='Cylinder Rental List',Code='CR 1',Starting Date='',Package Code='',Business Code=''
Debugging the code, it seems that stops after copying the second field...
i'm trying to copy all fields from one rref to another (as rref.transferfields does not exist :evil: )
thanks in advance
0
Answers
-
I think the primary key of your tables exists of multiple fields. So you INSERT the record after filling up the first primary-key field with the others still blank.
Then you fill up the second primary-key field and do a MODIFY. But the record doesn't exist because you saved it the previous loop.
So copy first ALL fields to your history-record and then do an INSERT. (if your primary key existed of only 1 field, it would work, but VERY slow because you do a MODIFY after each field. Now I don't do MODIFY anymore but only an INSERT.CLEAR(RecRef); CLEAR(FieldRef); CLEAR(TBField); RecRef.OPEN(INTTableNo); RecRefHT.OPEN(INTHistTableNo); IF RecRef.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT RecRefHT.INIT; TBField.RESET; TBField.SETRANGE(TableNo,INTHistTableNo); IF TBField.FINDSET(FALSE,FALSE) THEN BEGIN REPEAT FieldRef := RecRef.FIELD(TBField."No."); FieldRefHT := RecRefHT.FIELD(TBField."No."); FieldRefHT.VALUE := FieldRef.VALUE; UNTIL TBField.NEXT = 0; RecRefHT.INSERT; UNTIL RecRef.NEXT = 0; END;
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
:shock:
you're perfectly right...and believe or not, the code you wrote was the first version of my program...and it didn't work!!
i tried to rewrite it and it worked! :shock:
maybe i putted thisRecRefHT.INSERT;
IN the loop without noticing it ](*,) ](*,) ](*,) ](*,)
thank you!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions