Update main form from subform

itownson1

Registered User.
Local time
Yesterday, 21:26
Joined
Mar 20, 2019
Messages
43
Hi everyone

I currently have a main form that prints through a report to a label printer.

I have now added a subform that will contain the weights. So each time a weight is recorded it tabs down and records the next weight.
I want a field on the main form to pick up the weight in the latest subform field, so that it prints the latest weight on the label.

Hope that make sense?
 
Hi. Is there a way to sort the data in the subform so the main form can tell which record was the last one entered? If not, maybe you could add another field to the subform to designate which weight should be printed.
 
20190502_134256.jpg

As the weights are being added 1 - 10 in the subform, I want the "Weight" field in the main form to auto update.

Hope this makes more sense with the image.
 
View attachment 74766

As the weights are being added 1 - 10 in the subform, I want the "Weight" field in the main form to auto update.

Hope this makes more sense with the image.
Ah, the subform is probably unbound then. In the AfterUpdate event of each textbox in the subform, you can try something like this:
Code:
Me.Parent.Weight=Me.TextboxName
Hope it helps...
 
I couldn't get that to work.
The subform is a bound for linked to a table.
 
I couldn't get that to work.
The subform is a bound for linked to a table.
Hi. What does "couldn't get that to work" mean? Were you getting any errors? Did you replace the object names in the code with the correct ones from your database? Are you able to post a sample copy of your db with test data?
 
I think you ought to be doing this the other way. You ought to be printing FROM the subform, which would automatically know all the data relative to the parent.

This assumes that the subform is indeed related to the parent, and it isn't just another form.

In passing, it's dangerous to assume that the order of records in any form is significant, and assuming that the selected record on the subform is the one you want is not guaranteed. eg, what if you navigated to another row in the subform, or resorted the subform.

If the records in the subform have a date stamp, then you can find the ID of the record with the latest date stamp with a dlookup, and then use another dlookup to find the weight associated with the record. So you are getting the info from the tables, not from the subform.
 
Morning

Sorry, I should have been more descriptive. As I entered the value in the field, it didn't update the text box.
I am now realising how pathetic I am at trying to explain things.

Looking at it a different way, forgetting forms and subforms.
If I have 10 fields in a report that are bound to a table. These are weights taken from a scale. 2.5kg, 2.6kg etc
Can I have another field or text box in the same form that will be updated as the weights are being added.
WeightField1 = 2.5 therefore Textbox1 = 2.5
WeightField2 = 2.6 therefore Textbox1 = 2.6
WeightField3 = 2.5 therefore Textbox1 = 2.5
WeightField4 = 2.4 therefore Textbox1 = 2.4
WeightField5 = 2.5 therefore Textbox1 = 2.5
WeightField6 = 2.7 therefore Textbox1 = 2.7
WeightField7 = 2.3 therefore Textbox1 = 2.3
WeightField8 = 2.2 therefore Textbox1 = 2.2
WeightField9 = 2.7 therefore Textbox1 = 2.7
WeightField10 = 2.5 therefore Textbox1 = 2.5
 
as you enter a value, in the field's afterupdate event you can do

Parent!parentcontrolname=mycontrolname

ie you need the parent, but then replace the other bits with your own control names.
it will also update if you go back and edit other fields though.
 
Soooooooo If I put the following code into the afterupdate event of Field W1 would that mean that anything entered into Field W1 would update Field W10?

Parent!W10=W1

I am so sorry for my naivety on this matter.
 
Soooooooo If I put the following code into the afterupdate event of Field W1 would that mean that anything entered into Field W1 would update Field W10?

Parent!W10=W1

I am so sorry for my naivety on this matter.
It would really be easier to help you if you could post a demo db. Are you not able to do it? I gave you the same suggestion earlier, but you said it didn't work. So, there must be something we can't see from here.
 
Soooooooo If I put the following code into the afterupdate event of Field W1 would that mean that anything entered into Field W1 would update Field W10?

Parent!W10=W1

I am so sorry for my naivety on this matter.


Strictly controls, not fields
if control W10 was a control on the main form, then and Control W1 was a control on the subform, then putting

Parent!W10=W1 in the after update event for control F1 on the subform would set the named control on the parent accordingly

However, I thought controls F1 thru F10 were on the subform, or alternatively there was a control called "Weight" on the subform, and you had 10 rows of data, so the control "Weight" weight would apply to whichever is the active row.

As TheDBGuy has pointed out, we aren't really sure what is going on, so all of this is just surmising.
 

Users who are viewing this thread

Back
Top Bottom