Table of contents
TOC
折叠目录
展开目录

Application.DVar 方法 (访问)Application.DVar Method (Access)

office 365 dev account|上次更新日期: 2018/4/3
|
2 参与人员

计算指定记录集(即域)中抽样的方差的估计值。Estimates the variance across a sample in a specified set of records (a domain).

语法Syntax

expression.expression.DVar(* * Expr,* *,* 条件)DVar( ** Expr, ** Domain, ** Criteria* )

expression:表示 Application 对象的变量。expression A variable that represents an Application object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
ExprExpr必需RequiredStringString表达式,用于标识要在其中计算方差的数值字段。An expression that identifies the numeric field on which you want to find the variance.它可以是标识表或查询中的字段的字符串表达式,也可以是执行字段中数据计算的表达式。It can be a string expression identifying a field from a table or query, or it can be an expression that performs a calculation on data in that field .在_expr_中可以包括表、 窗体、 常量或函数上的控件中字段的名称。In expr, you can include the name field in a table, a control on a form, a constant, or a function.如果_expr_包含一个函数,它可以是内置的或用户定义的但不是能是其他域聚合函数或 SQL 聚合函数。If expr includes a function, it can be either built-in or user-defined, but not another domain aggregate or SQL aggregate function.Expr_中的任何字段都必须是数值字段。Any field included in _expr must be a numeric field.
DomainDomain必需RequiredStringString字符串表达式,用于标识组成域的记录集。可以是表名称或不需要参数的查询的查询名称。A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.
条件Criteria可选OptionalVariantVariant可选的字符串表达式,用于限制DVar函数执行对象的数据范围。An optional string expression used to restrict the range of data on which the DVar function is performed.例如,条件_通常是相当于在 SQL 表达式中,不带有单词 WHERE 子句中。For example, _criteria is often equivalent to the WHERE clause in an SQL expression, without the word WHERE.如果省略_条件_,使用DVar函数计算_expr_对整个域。If criteria is omitted, the DVar function evaluates expr against the entire domain.在_条件_中包含的任何字段还必须在_域_; 域否则使用DVar函数将返回NullAny field that is included in criteria must also be a field in domain; otherwise the DVar function returns a Null.

返回值Return Value

VariantVariant

注解Remarks

例如,可以使用DVar函数来计算一组学生考试成绩的方差。For example, you could use the DVar function to calculate the variance across a set of students' test scores.

如果_域_是指少于两个记录或记录少于两个满足_条件_,如果DVar函数返回Null,指示不能计算方差。If domain refers to fewer than two records or if fewer than two records satisfy criteria, the DVar functions return a Null, indicating that a variance can't be calculated.

无论是在宏、 模块、 查询表达式或计算的控件中使用DVar函数中使用,必须构造_criteria_参数,小心以确保能够正确地进行计算。Whether you use the DVar function in a macro, module, query expression, or calculated control, you must construct the criteria argument carefully to ensure that it will be evaluated correctly.

使用DVar函数可用于在查询中,或更新查询的更新到行中的计算的字段表达式中的选择查询的条件行中指定条件。You can use the DVar function to specify criteria in the Criteria row of a select query, in a calculated field expression in a query, or in the Update To row of an update query.

请注意 您可以在总计查询的计算的字段表达式中使用DVar函数或Var函数。Note You can use the DVar function or the Var function in a calculated field expression in a totals query.如果使用DVar函数,则先进行数据分组,计算值。If you use the DVar function, values are calculated before data is grouped.如果使用Var函数,则会将数据分组之后计算字段表达式中的值。If you use the Var function, the data is grouped before values in the field expression are evaluated.

当需要指定_条件_来限制函数执行对象的数据范围时,请在计算控件中使用DVar函数。Use the DVar function in a calculated control when you need to specify criteria to restrict the range of data on which the function is performed.例如,要显示的要发往 California 的订单的方差,请将文本框的控件来源属性设置为以下表达式:For example, to display a variance for orders to be shipped to California, set the ControlSource property of a text box to the following expression:

=DVar("[Freight]", "Orders", "[ShipRegion] = 'CA'")

如果您只是想要在_域_中的所有记录计算标准偏差,使用VarVarP函数。If you simply want to find the standard deviation across all records in domain, use the Var or VarP function.

示例Example

下面的示例返回运往英国的订单的总体样本及样本总体的方差的估计值。The following example returns estimates of the variance for a population and a population sample for orders shipped to the United Kingdom.域是订单表。The domain is an Orders table.Criteria_参数限制生成的记录集的货主国家等于英国。The _criteria argument restricts the resulting set of records to those for which ShipCountry equals UK.

Dim dblX As Double 
Dim dblY As Double 

' Sample estimate. 
dblX = DVar("[Freight]", "Orders", "[ShipCountry] = 'UK'") 

' Population estimate. 
dblY = DVarP("[Freight]", "Orders", "[ShipCountry] = 'UK'")

下一个示例通过使用变量,返回估计值strCountry,在_criteria_参数中。The next example returns estimates by using a variable, strCountry, in the criteria argument.注意单引号 (') 引起来包含在字符串表达式中,这样在进行字符串连接时,字面字符串UK将括在单引号中。Note that single quotation marks (') are included in the string expression, so that when the strings are concatenated, the string literal UK will be enclosed in single quotation marks.

Dim strCountry As String| 
Dim dblX As Double 

strCountry = "UK" 

dblX = DVar("[Freight]", "Orders", "[ShipCountry] = '" _ 
    &; strCountry &; "'")

下面的示例演示如何使用DVar函数中使用各种类型的条件。The following examples show how to use various types of criteria with the DVar function.

示例代码提供方:社区成员图标UtterAccess 社区Sample code provided by:Community Member Icon TheUtterAccess community

    ' ***************************
    ' Typical Use
    ' Numerical values. Replace "number" with the number to use.
    variable = DVar("[FieldName]", "TableName", "[Criteria] = number")

    ' Strings.
    ' Numerical values. Replace "string" with the string to use.
    variable = DVar("[FieldName]", "TableName", "[Criteria]= 'string'")

    ' Dates. Replace "date" with the string to use.
    variable = DVar("[FieldName]", "TableName", "[Criteria]= #date#")
    ' ***************************

    ' ***************************
    ' Referring to a control on a form
    ' Numerical values
    variable = DVar("[FieldName]", "TableName", "[Criteria] = " &; Forms!FormName!ControlName)

    ' Strings
    variable = DVar("[FieldName]", "TableName", "[Criteria] = '" &; Forms!FormName!ControlName &; "'")

    ' Dates
    variable = DVar("[FieldName]", "TableName", "[Criteria] = #" &; Forms!FormName!ControlName &; "#")
    ' ***************************

    ' ***************************
    ' Combinations
    ' Multiple types of criteria
    variable = DVar("[FieldName]", "TableName", "[Criteria1] = " &; Forms![FormName]![Control1] _
             &; " AND [Criteria2] = '" &; Forms![FormName]![Control2] &; "'" _
            &; " AND [Criteria3] =#" &; Forms![FormName]![Control3] &; "#")

    ' Use two fields from a single record.
    variable = DVar("[LastName] &; ', ' &; [FirstName]", "tblPeople", "[PrimaryKey] = 7")

    ' Expressions
    variable = DVar("[Field1] + [Field2]", "tableName", "[PrimaryKey] = 7")

    ' Control Structures
    variable = DVar("IIf([LastName] Like 'Smith', 'True', 'False')", "tableName", "[PrimaryKey] = 7")
    ' ***************************

关于参与者About the Contributors

UtterAccess 是主要的 Microsoft Access Wiki 和帮助论坛。单击此处即可加入。UtterAccess is the premier Microsoft Access wiki and help forum. Click here to join.

另请参阅See also

概念Concepts

Application 对象Application Object

© 2018 Microsoft