Subform unbound textbox value not updating on main form open (1 Viewer)

Ginny2222

Ginny
Local time
Today, 05:20
Joined
Oct 27, 2007
Messages
108
Hi,
I have a subform which is linked to a table on which I have a set of comboboxes and textboxes. When data in the comboboxes is chosen, the textboxes populate with numbers and the underlying table is populated.

I also have an unbound textbox which calculates using a function the sum of the values in the textboxes. I don't need to store this value, it's only for display. When I open the subform independently the value in this unbound textbox shows correctly, but when I open it using the main form the value shows as 0, and only updates when I choose something in one of the comboboxes. I also tried calling the function from the main form, but that definitely sets the value to 0.

I have tried requerying the controls from the main form on open/load etc. What am I missing here???

Help appreciated.
Ginny
 

RuralGuy

AWF VIP
Local time
Yesterday, 22:20
Joined
Jul 2, 2005
Messages
13,826
Are the rest of the controls on the SubForm populating correctly? What is the formula you have in your "unbound" textbox?
 

Ginny2222

Ginny
Local time
Today, 05:20
Joined
Oct 27, 2007
Messages
108
Hi RuralGuy

Thanks for replying. Yes, all other controls are working and displaying values correctly. The underlying tables get updated also. I have the calculation for the unbound textbox in the Public Function within the form. I call the function in the OnOpen event on the form. So I know that works fine.

My problem is that this is a subform and I can't seem to call the function from the main form. I haven't tried putting it in a module. Would this be where I am going wrong? Should Forms!MainForm!SubForm.FunctionName work from the main form and where would I put it.

Kind Regards
Ginny
 

missinglinq

AWF VIP
Local time
Today, 00:20
Joined
Jun 20, 2003
Messages
6,423
As the 'Old Man of the Mountain' said, we really need to see how you're doing this calculation, not just that you're calling 'a function.' If this involves a Calculated Field, ReCalc is probably more appropriate than Requery.

Also, the OnOpen event is almost always to soon to call an event that involves assigning a Value to a Control. OnLoad is usually the event of choice.

And what, exactly, is 'the Public Function within the form?'

Linq ;0)>
 
Last edited:

Ginny2222

Ginny
Local time
Today, 05:20
Joined
Oct 27, 2007
Messages
108
Public Function Update_Hours()
Dim rslt As Double
rslt = 0
rslt = Nz(Textbox1, 0) + Nz(Textbox2, 0) ...
me.hoursTextbox.Value = rslt
End Function

I tried putting the calculation directly into the control of the hoursTextbox, but when I opened the form which populate with the data from the underlying tables this calculation wouldn't update until I changed an item in a related combobox. The function call on the form OnOpen works.

My problem is that this is a subform. When I open the main form the hoursTextbox displays 0. I then have to change one of the comboboxes to call the function.

If this isn't making sense, I'll try a sample and upload it. Thanks for taking the time.

rgs
Ginny
 

Ginny2222

Ginny
Local time
Today, 05:20
Joined
Oct 27, 2007
Messages
108
Yes, thank you. I was leaving out the .Form. before the function and I had it in the On Open event. I tried it in the On Load and all is now working!!!

Thanks to both of you for the help. (RuralGuy, you have helped me before :), as always, very grateful.

rgs
Ginny
 

RuralGuy

AWF VIP
Local time
Yesterday, 22:20
Joined
Jul 2, 2005
Messages
13,826
Linq and I are just glad you got it sorted. Take care.
 

Users who are viewing this thread

Top Bottom