Update field on Main Form

aardvark
Lounger
Posts: 47
Joined: 09 Feb 2010, 11:30
Location: OH USA

Update field on Main Form

Post by aardvark »

Greetings all:

I have a field on a subform where I enter an amount. I need assistance in figuring out how to update a field on the main form based on my entry on the subform. I will need to + or - the amount on the main form based on the amount in the subform. I am using this, to no avail, in the AfterUpdate Event of the subform field:

Private Sub Receipt_Adjustment_AfterUpdate()

Forms!frmInventoryNew!OnHand = Forms!frmInventoryNew!OnHand + Forms!frmInventoryNew!frmAdjustments!Receipt_Adjustment

End Sub

Any and all assistance is greatly appreciated. TIA

Bill

aardvark
Lounger
Posts: 47
Joined: 09 Feb 2010, 11:30
Location: OH USA

Re: Update field on Main Form

Post by aardvark »

After further checking, this seems to work after all. Thanks anyway.

User avatar
HansV
Administrator
Posts: 74162
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Update field on Main Form

Post by HansV »

Glad it's working. You could simplify the code slightly:

Code: Select all

Private Sub Receipt_Adjustment_AfterUpdate()
  Me.Parent!OnHand = Me.Parent!OnHand + Me!Receipt_Adjustment
End Sub
Parent, when used in code behind the subform, refers to the main form. The advantage is that you don't have to specify the name of the main form or subform, so you won't have to edit the code if you rename either.
Regards,
Hans

aardvark
Lounger
Posts: 47
Joined: 09 Feb 2010, 11:30
Location: OH USA

Re: Update field on Main Form

Post by aardvark »

Thanks for the tip, Hans. I'll give it a try.