Reference Subform control within the subform in Ms Access

Hi people There!

I having problems assigning a bound control within a sub form called sfrmCostofSales subform] see the photo below . I want a control called stdcost to be updated by un bound control called txtperformance which carries special calculation for cost of sales , I tried the VBA code below , but nothing is working:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.StdCost = Forms![frmCustomerInvoice]![sfrmCostofSales subform].Form![txtPerformance]
End Sub

The parent form is called frmCustomerInvoice , could it be I'm using a wrong event.

Instead of entering calculation of cost of sales per unit manually I want this control called stdCost which is bound to the table to be update by this unbound control within the datasheete subform called sfrmCostofSales subform] which calculate the correct cost of sales

Kindly help!



Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
This should work - but [sfrmCostofSales subform] must be name of the subform control, not the subform itself:

Private Sub Form_BeforeInsert(Cancel As Integer)

    Me!StdCost.Value = Me![sfrmCostofSales subform].Form![txtPerformance].Value

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertConsultingCommented:

In your main form, there is a control holding the subform, and this  control have a Form property giving you access to the held form.
So basically, the syntax is:

Open in new window

Side note:
Access give the sub form control holder's name the same name as the sub form (ehence the confusion), but you can name it whatever you like.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.