2010/05/01

access2010 データマクロで累計 -AfterUpdate-

基本的なところは、挿入後と同じ。 
IfブロックでUpdate("f_num")検査→f_numフィールドが更新されたら
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application">
  <DataMacro Event="AfterUpdate">
    <Statements>
      <ConditionalBlock>
        <If>
          <Condition>Updated("f_num")</Condition>
          <Statements>
            <ForEachRecord>
              <Data Alias="t1_0">
                <Reference>t1</Reference>
              </Data>
              <Statements>
                <Action Name="SetLocalVar">
                  <Argument Name="Name">tmpsub</Argument>
                  <Argument Name="Value">0</Argument>
                </Action>
                <ForEachRecord>
                  <Data Alias="t1_1">
                    <Reference>t1</Reference>
                    <WhereCondition>[t1_1].[ID]&lt;=[t1_0].[ID]</WhereCondition>
                  </Data>
                  <Statements>
                    <Action Name="SetLocalVar">
                      <Argument Name="Name">tmpsub</Argument>
                      <Argument Name="Value">[t1_1].[f_num]+[tmpsub]</Argument>
                    </Action>
                  </Statements>
                </ForEachRecord>
                <EditRecord>
                  <Data />
                  <Statements>
                    <Action Name="SetField">
                      <Argument Name="Field">t1_0.f_sum</Argument>
                      <Argument Name="Value">[tmpsub]</Argument>
                    </Action>
                  </Statements>
                </EditRecord>
              </Statements>
            </ForEachRecord>
          </Statements>
        </If>
      </ConditionalBlock>
    </Statements>
  </DataMacro>
</DataMacros>


0 件のコメント: