Solved How to reference a Subform from the parent form (1 Viewer)

nector

Member
Local time
Today, 08:51
Joined
Jan 21, 2020
Messages
368
Hi

I'm trying to reference the subform from the parent form so that a figure from the hidden form can be capture on the subform , but I keep on getting an error that control cannot be found : Forms![frmGrn].Form![SfrmPurchasesOrdersDetailslines Subform]![GRNID


Code:
Private Sub CboAttachGRN_AfterUpdate()
Forms![frmGrn].Form![SfrmPurchasesOrdersDetailslines Subform]![GRNID] = [Forms]![frmGrn]![GRNID]
End Sub

Where do I go wrong?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:51
Joined
May 7, 2009
Messages
19,243
Code:
Private Sub CboAttachGRN_AfterUpdate()
Forms![frmGrn]![SfrmPurchasesOrdersDetailslines Subform].Form![GRNID] = [Forms]![frmGrn]![GRNID]
End Sub
 

ebs17

Well-known member
Local time
Today, 07:51
Joined
Feb 7, 2020
Messages
1,946
Code:
Me.[SfrmPurchasesOrdersDetailslines Subform].Form.GRNID = ...
First the name of the control, then its form property.
If you dispense with the unspeakable brackets, you gain clarity.
 

nector

Member
Local time
Today, 08:51
Joined
Jan 21, 2020
Messages
368
Ok many thanks this works perfect, but its updating only one line, or first line, how do I update all active lines?

GRN UPDATES 2023.png

See where 41 is, I want the other remaining two line to updated as well.
 

Josef P.

Well-known member
Local time
Today, 07:51
Joined
Feb 2, 2023
Messages
826
The value of the control in the subform always refers to the current record only.
=>
a) Update statement or pass through all data records
b) Reconsider data model, if the value is always valid for all data records of a PO.
 

nector

Member
Local time
Today, 08:51
Joined
Jan 21, 2020
Messages
368
The data is valid for all the model, that is why we select the correct number from the combobox, the problem is how to make it update all
 

Josef P.

Well-known member
Local time
Today, 07:51
Joined
Feb 2, 2023
Messages
826
Szenario a)
(schematic code only)
Code:
private sub YourCombobox_AfterUpdate()
      SetGrnIdToSubFormRecords me.YourCombobox.Value
      YourSubForm.Requery
end sub

private Sub SetGrnIdToSubFormRecords(byval NewGrnId as long)
    dim UpdateSql as String
    UpdateSql = "update Po_item_table ... where PoId = ... "
    currentdb.Execute UpdateSql, dbfailonerror
end sub

Szenario b)
Only the one record in the PO header table needs to be changed.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:51
Joined
May 7, 2009
Messages
19,243
Code:
Private Sub CboAttachGRN_AfterUpdate()
With Me.[SfrmPurchasesOrdersDetailslines Subform].Form.RecordsetClone
    If Not (.BOF And .EOF) Then
        .MoveFirst
    End If
    Do Until .EOF
        .Edit
        !GRNID = [Forms]![frmGrn]![GRNID]
        .Update
        .MoveNext
    Loop
End With
End Sub
 

nector

Member
Local time
Today, 08:51
Joined
Jan 21, 2020
Messages
368

arnelgp

This is excellent programing you have solved my problem once and for all

many to thanks to

Regards

Chris
 

Josef P.

Well-known member
Local time
Today, 07:51
Joined
Feb 2, 2023
Messages
826
First of all: I don't want to question arnelgp's solution. This is a very easy to follow implementation of your requirement.

If I remember correctly, you are using MS SQL Server.
Compare the data transfer between the updates per record and an update statement. (Writing is more expensive than reading).
This will not be relevant for a few records. But you could come up with the idea to always work this way and maybe let several users work with the database at the same time. ;)

BTW: I would give preference to normalization.
 

Users who are viewing this thread

Top Bottom