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

Report.RecordSource 属性 (访问)Report.RecordSource Property (Access)

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

可以使用的记录源属性指定的报表的数据源。You can use the RecordSource property to specify the source of the data for a report.读/写 StringRead/write String.

语法Syntax

expression.expression.RecordSourceRecordSource

表达式_一个表示报表对象的变量。_expression A variable that represents a Report object.

注解Remarks

表名、 查询名称或 SQL 语句可以为记录源属性设置。The RecordSource property setting can be a table name, a query name, or an SQL statement.例如,您可以使用以下设置。For example, you can use the following settings.

设置示例Sample setting说明Description
雇员Employees一个将"雇员"表指定为数据源的表名称。A table name specifying the Employees table as the source of data.
SELECT Orders!OrderDate FROM Orders;在订单表的订购日期字段指定为数据源的 SQL 语句。An SQL statement specifying the OrderDate field on the Orders table as the source of data.可以通过将控件的控件来源属性设置为订购日期到订单表中的订购日期字段绑定的窗体或报表上的控件。You can bind a control on the form or report to the OrderDate field in the Orders table by setting the control's ControlSource property to OrderDate.
注意

更改的已打开窗体或报表的记录源会自动对基础数据进行重新查询。Changing the record source of an open form or report causes an automatic requery of the underlying data.如果在运行时设置窗体的记录集属性,将更新该窗体的记录源属性。If a form's Recordset property is set at runtime, the form's RecordSource property is updated.

创建窗体或报表之后,可以通过更改记录源属性来更改其数据源。After you have created a form or report, you can change its source of data by changing the RecordSource property.还是很有用,如果您想要创建一个可重复使用的窗体或报表的记录源属性。The RecordSource property is also useful if you want to create a reusable form or report.例如,您可以创建窗体包含标准设计,然后将窗体复制并更改记录源属性,以显示不同的表、 查询或 SQL 语句中的数据。For example, you could create a form that incorporates a standard design, then copy the form and change the RecordSource property to display data from a different table, query, or SQL statement.

示例Example

下面的示例将窗体的记录源属性设置为客户表:The following example sets a form's RecordSource property to the Customers table:

Forms!frmCustomers.RecordSource = "Customers"


下一个示例将更改为客户表中,具体取决于在选定的公司名称中的单个记录窗体的记录源cmboCompanyName组合框控件。The next example changes a form's record source to a single record in the Customers table, depending on the company name selected in the cmboCompanyName combo box control.组合框的内容由返回客户 ID (在绑定列中) 和公司名称的 SQL 语句。The combo box is filled by an SQL statement that returns the customer ID (in the bound column) and the company name.客户 id 的文本框数据类型。The CustomerID has a Text data type.

Sub cmboCompanyName_AfterUpdate() 
    Dim strNewRecord As String 
    strNewRecord = "SELECT * FROM Customers " _ 
        &; " WHERE CustomerID = '" _ 
        &; Me!cmboCompanyName.Value &; "'" 
    Me.RecordSource = strNewRecord 
End Sub

下面的示例演示如何使用结构化查询语言 (SQL) 语句建立报表的数据源,因为它没有打开。The following example shows how to use a Structured Query Language (SQL) statement to establish the data source of a report as it is opened.

示例代码提供方:Microsoft Access 2010 程序员参考Sample code provided by: The Microsoft Access 2010 Programmer's Reference

Private Sub Report_Open(Cancel As Integer)

    On Error GoTo Error_Handler

    Me.Caption = ?My Application?

    DoCmd.OpenForm FormName:=?frmReportSelector_MemberList?, _
    Windowmode:=acDialog

    ?Cancel the report if ?cancel? was selected on the dialog form.

    If Forms!frmReportSelector_MemberList!txtContinue = ?no? Then
        Cancel = True
        GoTo Exit_Procedure
    End If
    Me.RecordSource = ReplaceWhereClause(Me.RecordSource, _
      Forms!frmReportSelector_MemberList!txtWhereClause)

Exit_Procedure:
    Exit Sub

Error_Handler:
    MsgBox Err.Number &; ?: ? &; Err.Description
    Resume Exit_Procedure
    Resume

End Sub

关于参与者About the contributors

Wrox Press 秉承程序员到程序员的理念。Wrox 书籍由程序员为程序员编写,Wrox 品牌意味着对实际编程问题的权威解决方案。Wrox Press is driven by the Programmer to Programmer philosophy. Wrox books are written by programmers for programmers, and the Wrox brand means authoritative solutions to real-world programming problems.

另请参阅See also

Report 对象Report Object

© 2018 Microsoft