Reference to other form elements or global variables?

M

Mr. Smith

Hi.

I have developed a budgeting application in Access 2003. It's been steadily
growing when it comes to forms/sub forms etc. I have a main form with a
"page" object with some 8 pages. In each page there is at least one sub
form. I need values from different sub forms to be updated between pages/sub
forms when they're changed.



I keep calling "load" sub's to refresh sub forms values, but as the load
sub's are pretty heavy sometimes, it's a lot of processing for updating just
one value.




As an example, the user are allowed to enter a "target" revenue value in
MainForm.tx_targetrevenue. After update on this textbox, I sould like to
update all references to this value/textbox. Setting the "Control source"
=Forms!MainForm!tx_targetrevenue on other text boxes are only updated "on
load" (as far as I can se....?)



Will I be better of structuring a set of global_variables which could be
used throughout the application, or is there a way to easily update referred
values without doing a "load" on the entire sub form.....



Thank you for your time, reading all this.



Any hints appreciated

Kind regards

Mr. Smith
 
M

mscertified

You don't need to update anything the user cannot see, so only update the
values when the page containg the values is displayed.
There is nothing wrong in using global variables if you want to but make
sure you check them before using them as previous errors can wipe them out.

-Dorian
 
K

Klatuu

Say No to Global variables. They are more trouble than benefit. All you
need to remeber is how to reference a control on a subform. Since all the
subforms are just controls on your main form, you use the following construct:

Me.SubForm1.Form.SomeControl = Me.MainForm.tx_targetrevenue

So if you want to update multiple controls on different subforms you could
use something like

With Me
.SubForm1.Form.SomeControl = Me.MainForm.tx_targetrevenue
.SubForm2.Form.AnotherControl = Me.MainForm.tx_targetrevenue
.SubForm3.Form.AnyControl = Me.MainForm.tx_targetrevenue
End With
 
D

Dale Fye

Mr. Smith,

As Dave mentioned, if the controls are not bound, then you really only need
to update them if they are visible. And even if they are bound, there is no
need to refresh every subform on a tab control at once. Instead, use the tab
controls Change event, something like:

Private sub tab_MyTab_Change()

'The value of the tab control is zero based, so the tab with the first
index
'is indexed at zero.
Select Case me.tab_MyTab.value
Case 0
'insert code here to requery a form or set a controls value, but
'only for those controls on the first tab
Case 1
'insert code here to requery a form or set a controls value, but
'only for those controls on the second tab
Case 2
'insert code here to requery a form or set a controls value, but
'only for those controls on the third tab
End Select

End Sub

HTH
Dale
 
M

Mr. Smith

Thanks all!
mscertified, Klatuu and Dale

I think I'll be abel to get a better approach now. I'll try to use
after_update subs on "key" text boxes to distribute changes.

Thanks again.

Mr. Smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top