Child subforms No Current Record (1 Viewer)

bentheimmigrant

Lost & confused
Local time
Today, 11:20
Joined
Aug 21, 2015
Messages
60
I have a Parent form with some continuous Child subforms. These forms allow additions, edits, and deletions.

When the user enters data into certain fields, AfterUpdate fires some VBA to do some maths, and populate some fields in the Parent form. When you go back and edit one of these fields in a Child, it works, but when you try to edit a second one, you get a "No Current Record" error.

It seems that interacting with the Parent loses the focus on the current record, and nothing can fix it until either the Parent or Child is requeried. I've tried clicking out of and back into the Child, but you have to requery.

I could add a requery to the VBA, but that will be extremely annoying to anyone trying to enter data, as they'll always lose their place.

Any advice on how to keep my current record active while also populating parent form fields?

TIA
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:20
Joined
Sep 12, 2006
Messages
15,613
I have a Parent form with some continuous Child subforms. These forms allow additions, edits, and deletions.

When the user enters data into certain fields, AfterUpdate fires some VBA to do some maths, and populate some fields in the Parent form. When you go back and edit one of these fields in a Child, it works, but when you try to edit a second one, you get a "No Current Record" error.

It seems that interacting with the Parent loses the focus on the current record, and nothing can fix it until either the Parent or Child is requeried. I've tried clicking out of and back into the Child, but you have to requery.

I could add a requery to the VBA, but that will be extremely annoying to anyone trying to enter data, as they'll always lose their place.

Any advice on how to keep my current record active while also populating parent form fields?

TIA

bit in bold


this might be the culprit. A sub-form/sub-record shouldn't need to modify the main record. That's the point of the main record-subrecord structure.
 

bentheimmigrant

Lost & confused
Local time
Today, 11:20
Joined
Aug 21, 2015
Messages
60
Ok... So does the child recordset have access to all the fields in the parent recordset? The parent holds the overall cost (part of tblProject, say), while tblCosts includes the itemised costs. The parent just queries tblProject.* on Project_id (single record) while the children query tblCosts.*. Project_id is, unsurprisingly, the parent/child link field, or whatever it's called.

How does one they change a field in the parent from the child?

Thanks.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:20
Joined
Jul 9, 2003
Messages
16,244
If I interpret your problem correctly you are saying that events in your subform which operate code in the main form, cause you to lose the position you are at in the subform display. I'm assuming "Datasheet View". I don't use this method myself but I am aware of it. My understanding is, you record the position you are at first, then run your VBA code, then return to that position. There's a thread here about the method.

SetFocus to specific row of datasheet?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:20
Joined
Sep 12, 2006
Messages
15,613
Ok... So does the child recordset have access to all the fields in the parent recordset? The parent holds the overall cost (part of tblProject, say), while tblCosts includes the itemised costs. The parent just queries tblProject.* on Project_id (single record) while the children query tblCosts.*. Project_id is, unsurprisingly, the parent/child link field, or whatever it's called.

How does one they change a field in the parent from the child?

Thanks.

bits in bold.

strictly speaking
a) the child is dependent on the parent record, and does not need to access to any other field in the parent record
b) there is no need to ever change anything in the parent record.

anything else is most likely reflecting a non well-normalised database.

eg. there is no need for the project to hold the overall cost. just get it when you need it by summing the cost of the project elements. Seriously. That way, your project cost is always accurate, and you don't have to have "artificial" processes to maintain the overall project cost - which you may find may go wrong from time to time.
 

bentheimmigrant

Lost & confused
Local time
Today, 11:20
Joined
Aug 21, 2015
Messages
60
But I specifically want to display that aggregate cost on the parent. So, even if it were a calculated value, I'd still have to send a number or requery command to the parent, wouldn't I?

Also, no. Although I would prefer to limit what the user can do, I've been specifically asked not to. If they want to just type a number into the total project cost (which they may well do early on, when no detailed costing has been done), they can. It's a very... fluid workflow, and not my place to change. So the project MUST hold the total cost.

To clarify, all I'm doing is writing a number to a (bound) textbox on the parent. The subform is a continuous subform, and sends the number to the parent.textbox as part of the subform field's AfterUpdate. I don't lose my place on the form unless I requery, but I do get a "no current record" error when I subsequently type in a subform field (but only on lines that have already run the AfterUpdate code).
 

Users who are viewing this thread

Top Bottom