FindRecord 宏操作

适用于:Access 2013、Office 2013

可以使用 FindRecord 操作查找符合由 FindRecord 参数指定的条件的第一个数据实例。 此数据可能在当前记录中,也可能在当前记录之前或之后的记录中,或者在第一条记录中。 您可以在活动表数据表、查询数据表、窗体数据表或窗体中查找记录。

Setting

FindRecord 操作具有下列参数。

操作参数

说明

查找内容

指定要在记录中查找的数据。 请在“宏生成器”窗格“操作参数”部分的“查找内容”框中输入要查找的文本、数字或日期,或者键入以等号 (=) 开头的表达式。 可以使用通配符。 这是一个必选参数。

匹配

指定数据在字段中的位置。 可以指定搜索位于字段任何部分的数据(“字段任何部分”)、填充整个字段的数据(“整个字段”)或位于字段开头的数据(“字段开头”)。 默认值为“整个字段”

区分大小写

指定搜索是否区分大小写。 请单击 "是"(执行区分大小写的搜索)或 "否"(进行搜索时不精确匹配大写和小写字母)。 默认值为 "否"

搜索

指定搜索方式:从当前记录开始向上搜索到记录开头(“向上”);向下搜索到记录末尾(“向下”);或者向下搜索到记录末尾,然后再从记录开头开始搜索到当前记录,从而搜索所有记录(“全部”)。 默认值为“全部”

格式化搜索

Specifies whether the search includes formatted data. Click Yes (Microsoft Office Access 2007 searches for the data as it is formatted and displayed in the field) or No (Access searches for the data as it is stored in the database, which isn't always the same as it's displayed). The default is No. You can use this feature to restrict the search to data in a particular format. For example, click Yes and type 1,234 in the Find What argument to find a value of 1,234 in a field formatted to include commas. Click No if you want to type 1234 to search for the data in this field. To search for dates, click Yes to find a date exactly as it is formatted, such as 08-July-2003. If you click No, enter the date for the Find What argument in the format that is set in the regional settings in Windows Control Panel. This format is shown in the Short date format box found on the Date tab in the regional settings. For example, if the Short date format box is set to M/d/yy, you can enter 7/8/03, and Access will find all entries in a Date field that correspond to July 8, 2003, regardless of how this field is formatted.

注意:仅当当前字段是绑定控件、Match 参数设置为“整个字段”、“仅当前字段”参数设置为“是”和“匹配大小写”参数设置为“否”时,“搜索格式”参数才会生效。

If you set Match Case to Yes or Only Current Field to No, you must also set Search As Formatted to Yes.

只搜索当前字段

指定是将搜索限制在每个记录内的当前字段,还是包括每个记录内的所有字段。 在当前字段中进行搜索的速度更快。 请单击 "是"(将搜索限制在当前字段)或 "否"(在每个记录内的所有字段中进行搜索)。 默认值为 "是"

查找第一个

指定搜索是从第一条记录开始,还是从当前记录开始。 请单击 "是"(从第一条记录开始)或 "否"(从当前记录开始)。 默认值为“是”

备注

When a macro runs the FindRecord action, Access searches for the specified data in the records (the order of the search is determined by the setting of the Search argument). When Access finds the specified data, the data is selected in the record.

FindRecord 操作等效于在 "开始" 选项卡上单击 "查找",其参数与 "查找和替换" 对话框中的选项相同。 如果在"宏生成器"窗格中设置了 FindRecord 参数,然后运行宏,则您将看到单击 "查找""查找和替换" 对话框中选择的相应选项。

在数据库会话过程中,Access 会保留最近的 FindRecord 参数,因而您在使用 FindRecord 操作执行后续操作时无需重复输入相同的条件。 如果您将某个参数留空,Access 将使用该参数的最近设置,与在前一个 FindRecord 操作或 "查找和替换" 对话框中的设置相同。

当需要使用宏查找记录时,请使用 FindRecord 操作,而不是其参数设置为运行 "查找" 命令的 RunMenuCommand 操作。

注意

[!注释] 针对表、查询和窗体的 FindRecord 操作对应于 "开始" 选项卡上的 "查找" 命令,而不对应于"代码"窗口的 "编辑" 菜单上的 "查找" 命令。 不能使用 FindRecord 操作在模块中搜索文本。

在执行 FindRecord 操作时,如果当前选择的文本与搜索文本相同,则会从所选文本之后开始在包含该文本的同一字段和同一记录中进行搜索。 否则将从当前记录的起始位置开始搜索。 这样可以找到单个记录中可能出现的符合相同搜索条件的多个实例。

但请注意,如果使用命令按钮运行包含 FindRecord 操作的宏,则将重复找到搜索条件的第一个实例。 出现这种情况的原因是,单击命令按钮会将焦点从包含匹配值的字段中移走。 然后, FindRecord 操作将从记录开头开始搜索。 为了避免此问题,请使用不更改焦点的技术(例如自定义工具栏按钮或在 AutoKeys 宏中定义的组合键)运行宏,或在执行 FindRecord 操作之前将宏中的焦点设置为包含搜索条件的字段。

安全说明 安全说明
避免使用 SendKeys 语句或带敏感或机密信息的 AutoKeys 宏。 恶意用户可能会拦截键击并损害您的计算机和数据的安全性。

如果使用命令按钮运行包含 FindNext 操作的宏,也会出现同样的情况。

要在 Visual Basic for Applications (VBA) 模块中运行 FindRecord 操作,请使用 DoCmd 对象的 FindRecord 方法。

要进行更加复杂的搜索,您可能需要使用 SearchForRecord 宏操作。