SubForm modifying parent

Have been writing some “modules” for the coy I work for for the past couple of years. One of the things that has caused me no end of grief is modifying the “parent” record when in a subform. I know my terminlogy may not be accurate but when my code modifies parent (either MODIFY, INSERT, DELETE, RENAME, etc.) in a subform then get message "Another user has modified the Parent RecordTableName, Primary key1, Primarykey2, etc. please (and this not exact wording) refresh the database. I don’t know if I am making this clear. So here is an example, where I don’t have a problem. Say I create a report, the first DataItem is say the SalesHeaderTable and I assign it the name SHT for short. The report also has another dataitem indented for the Sales Line Table, SLT for short, so that, oh I forget the term, but the SHT is the parent of SLT or the SLT is the child of the SHT. Anyway as the report processes, get no problem if in the OnAfterGetRecord() (well any section, really) modifying the SHT when processing a line from the SLT. That is while processing a SLT might have to change, say a field on the SHT e.g. IF NOT(SLT.Finished) THEN BEGIN SHT.Complete:=FALSE; SHT.MODIFY; END; In a report with dataitems set up as noted no problem. The problem comes in when I try to do the same thing, in a Form-SubForm as I can’t figure out how to refer to the parent when in the child subform, and modify the parent form record without getting the message above. It does actually modify the parent but get the message which drives the EUs nuts. Me too for that matter. Using the SHT/SLT anology. User is looking at a form, using SHT table on the main form. The main form displays a subform showing the SLT for that SHT. Say now the user enters data for the sales line, and depending upon what is entered the Sales Header table may need to be modified/inserted/deleted/etc. If the main form is the active form the Rec and xRec refer to the SHT However, when the user clicks/types in the subform and it is therefore the active object, then Rec, xRec refer to the sales Line Table If I create a global/local in subform, call it SHT, for the Header Table and then write code along the lines of IF (User enters blah blah blah, or does X) THEN SHT.MODIFY; get the message as noted above. I undertand why it does that. Because when it goes back to parent form it now has two versions of SHT, one in the main form and the other I just called and modified. How do I stop this. How do I refer to the parent in the subform so that modifying it does not give message?

Mike, I am curious where you have placed your code? Are you calling the MODIFY/INSERT/DELETE routines from the Form object or the Table object for the Subform? I’ve found that you will often receive that error when trying to call a MODIFY/INSERT/DELETE to the Header record when calling from a Subform Form object, but when calling from the Subform Table object, I rarely get any hassles. Regards! Kristopher Webb Kelar Corporation, Canada

I need to be clear on this cause it has given me no end of hassles. So am I going to be deliberately dense. How do you actually call the parent in the sbu table. Do you create a variable (local or global) in the sub Table, lets call it recSHT or do you some how pass the header Rec variable to the sub table? If you create a variable in sub Table recSHT then you have 2 versions of the Table open, the one one the Main form and the one you have in the sub fomr table, does this not lead to same problem? You have header table, with records You have a “Header” form which shows the record/records on Header Table You have a Line Table, with records You have a SubForm which displays data from the Line Table, and is part of the Header Form I have been writing the code in the subform. You are saying to write the code in the Line Table or are you saying right the code in the Header Table? And that works? How do I filter in the sub table on the Header Table without essentially creating a Variable on Sub Table for the Header table, in which case I again have 2 versions of the header Table, the one on the Main Form and the one I have on the sub table. Won’t it give the same message? Because once again when the user leaves the subform, and now the Header Form is active, along with the original header Table, it will notice that the Header Table has been modified since last active (which it has) and give the message that another user has modified the table. As I mentioned we had a lot of customization done. This was done by Navision reseller. I have dug around in native Navision and what the reseller did and in the case of working with data on the sub Table thru a subform (cause there is other places were the user gets directly to the sub Table, in which case not through a subform) and the processing/data entry indicates a change is needed on header table the code (Native and reseller) does one of 2 things It waits until the main form is activated again, then runs a routine to make the change to Main table, or they added a field to the subtable, which from a simply storing info point of view should really be on the header table. That way the subforms never actaully modify the Main Table either thru the form itself or in the subtable. One example is when someone makes changes in sales lines on subform, it retotals subtotals, when the user gets back to the main form. The other case is we have a flag “Problem Order” and as it says, this applies to the whole order, but the reseller added a field to the sales line table for “Problem Order”. this is not efficient. Each line on the sales line table has a field called Problem Order, when really allwe need is the field on the Header table. It works but not efficient. The particular “module” I am working on now is/will be huge I need to save “space” on tables (otherwise the Table definition gets too big) so while adding a field to sub table works, I may find the table definition gets too big. Also, I need to make this thing as effecient as possible otherwise when it is used the user will have to come back in a year or 2 to get the results. The biggest complaint I get now is that it takes too long (about 3 seconds on a large order) and I am not even close to being done and I have it doing its “job” in a very simplified manner, kind of like a demo mode, if you will. Don’t get me wrong Kristopher, I am just paranoid I’ll mess something up. But I am going to try your idead.

Mike, You are correct. I am saying to use the Line table and create a recSHT variable there to do your work. The reason it doesn’t come back with that message is something to do with what order the forms and tables are updated after a change has been made. I think the tables get updated from the Line table using the recSHT variable, the MODIFY/INSERT/DELETE triggers run, then the events are returned to the form, which is going to call an update/refresh. At this point in time, I believe the whole form is going to get updated, and I’m not sure it cares if it is the subform or header form that the modification was made in. It’s just updating the whole form with the current tables. For you to make code changes in the subform instead of sub table, you are running the events out-of-order. I’m sure you could look through the ADG and see the Event Order and confirm all this for sure. I couldn’t be bothered today, but someday when I’m really bored HA!, I’ll sit down in the library and take a gander. hehe Regards! Kristopher Webb Kelar Corporation, Canada

OK, makes sense to me. Which is dangerous in and of itself. Thank you very much.

I have played around this a lot and the only way I have found that works with any certainty (and the way Navision seems to use) is to put code in the OnTimer Trigger of the Mainform that looks at the Subform lines - and totals them or whatever. Of course if you are using a flowfield for the total you only need to call an update on the control that holds the flowfield and Navision will re-calc the total. Be wary of calling an update to the whole form from the Timer trigger because whatever control is active will refresh too, meaning you can lose bits of what you are typing. I haven’t looked in any detail at the event-order though - any reference docs would be appreciated. Cheers, Nikolai L’Estrange

quote:


Originally posted by wlgnles: I have played around this a lot and the only way I have found that works with any certainty (and the way Navision seems to use) is to put code in the OnTimer Trigger of the Mainform that looks at the Subform lines - and totals them or whatever.


I have never liked the Timer functionality in Navision, or at least I’ve never found an appropriate project to use it. I understand what you’re getting at using this timer function, but I think most of my customers would find that unacceptable. I can just hear the phone calls coming in now… “I am in the middle of typing and suddenly the text changes!” hehe Although, sometimes some of our customers have a tendancy to go ape when stuff out of the ordinary happens, but you can’t really blame them… Regards! Kristopher Webb Kelar Corporation, Canada

quote:


I have never liked the Timer functionality in Navision, or at least I’ve never found an appropriate project to use it. I understand what you’re getting at using this timer function, but I think most of my customers would find that unacceptable. I can just hear the phone calls coming in now… “I am in the middle of typing and suddenly the text changes!” hehe Although, sometimes some of our customers have a tendancy to go ape when stuff out of the ordinary happens, but you can’t really blame them…


…and have you ever tried to debug a function accessed from a form with code in the OnTimer trigger and a frequent interval? And yes, we have had clients report the ‘Overwriting my own text as I type’ problem, so I would agree that this should be last of last resorts.