Hello Dr. Belhareth,
One way you could do this is with a mass update from the parent form. I built a sample application that has a parent named "NewForm" and a subform named "NewForm0". On the Parent Form there is one element named "CustNum". It holds the unique key for each record. The subform has three elements, "Pat_ID", "Metal Type" and "Result". "Metal Type" would be comparable to either your code or item element.
The code for the mass update is below.
** PROGRAMMING SECTION: [ GLOBAL CODE ] [] **
Stat gsFile as String
gsFile = @Insert("ToImport.txt")
** PROGRAMMING SECTION: [CustNum] [Mass Update] **
Var vData as String
Var vRecData as String
Var vItem as String
Var vCnt as Int
Var vLoop as Int
Var vRecCnt as Int
Var vRecLoop as Int
Var vQuit as Int
Var vResult as Double
SetStringArraySeparator(@Newline())
//Get all Data in the File for this Customer
vData = @SearchStringArray(gsFile, @Str(CustNum) + "..")
//Remove the data for this customer from the file as it is no longer needed.
gsFile = @DifferenceStringArray(gsFile, vData)
vCnt = @CountStringArray(vData)
vLoop = 1
vRecCnt= @FormResultSetTotal("NewForm0")
vRecLoop = 1
vQuit = 0
//Loop through the data from the text file
While vLoop <= vCnt
{
vRecData = @AccessStringArray(vData, vLoop)
RestoreStringArraySeparator()
//Parse apart
vItem = @AccessStringArray(vRecData, 2)
vResult = @AccessStringArray(vRecData, 3)
//Loop through the subform looking for the record that matches
While ((vRecLoop <= vRecCnt) And (vQuit = 0))
{
If @FormFieldValue("NewForm0", "Metal Type", vRecLoop) = vItem Then
{
//Record found. Lets put the result in the subform.
FormFieldValue("NewForm0", "Result", vRecLoop, vResult)
If @ToMoney(@FormFieldValue("NewForm0", "Result", vRecLoop)) <> vResult Then
{
Writeln("Failed to set the result Element on record " + vRecLoop)
}
vQuit = 1
}
vRecLoop = vRecLoop + 1
}
vRecLoop = 1
vQuit = 0
SetStringArraySeparator(@Newline())
vLoop = vLoop + 1
}
The file that was imported looks like this
1;Silver;1234
1;Plat;123.4
1;Iron;12.34
2;Tita;1
2;Alum;2
2;Plat;3
2;Silver;4
2;Gold;5
2;Ore;6
2;Iron;7
3;Silver;1
3;Iron;2
3;Tungsten;3
3;Alloy;4
3;Aluminum;5
If you would like to see the application that shows how to accomplish this, just send me an e-mail at support@lantica.com and I will be happy to send it your way along with the file for it to import.
As I was typing this it also occured to me that you don't have to be on the parent form at all. You could use a variation of the code above to do a mass update on the subform database itself.
-Ray