Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a form and wish to update a control to the result of two other controls, you can set the Control Source to ( <a href="http://office.microsoft.com/en-us/access-help/create-an-expression-HA001181384.aspx" rel="nofollow">http://office.microsoft.com/en-us/access-help/create-an-expression-HA001181384.aspx</a> ) :</p> <pre><code> =[Control1]+[Control2] </code></pre> <p>Control1 and Control2 can be bound to Field1 and Field2 by setting the Control Source for each to the relevant field name, however, you cannot bind that Control3 to Field3 because it is already set. If you wish to update Field3 on a form in this way, you need to use code in an event, the After Update event of Control1 and Control2 may suit. It is against normalization rules to store calculations, so you must consider if this is what you wish to do. In Access 2010, you can create a caluclated field (column), which is a different thing, in that it takes care of its own updating : <a href="http://msdn.microsoft.com/en-us/library/ff945943.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ff945943.aspx</a> </p> <p>As for default values, there are a few things to consider:</p> <ul> <li>You cannot set the default value in a table, AFAIK, to Field1+Field2</li> <li>The DefaultValue property is applied only when you add a new record. If you change the DefaultValue property, the change isn't automatically applied to existing records</li> <li>If the controls are on the same form, the control that's the source of the default value must appear earlier in the tab order than the control containing the expression.</li> </ul> <p>Also consider, if you use:</p> <pre><code>=Field1 + Field2 </code></pre> <p>You are referring to the underlying fields in the table, and this can lead to problems if Field1 and Field2 also appear on the form and can be updated. It would be better to use:</p> <pre><code>Me.MyControl.DefaultValue=Control1+Control2 </code></pre> <p>Where the controls are bound to Field1 and Field2. In VBA, this will mean that the default value will be set to the result of the calculation, which is unlikely to be what you want, more probably you want:</p> <pre><code>Me.MyControl.DefaultValue="=Control1+Control2" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload