LookupRecord Data Block
Last modified: July 28, 2015
Applies to: Access 2013 | Office 2013
In this article
Setting
Remarks
Example
About the Contributors
A LookupRecord data block performs a set of actions on a specific record.
Note
|
|---|
|
The LookupRecord data block is available only in Data Macros. |
The SetField action has the following arguments.
|
Argument |
Required |
Description |
||
|---|---|---|---|---|
|
In |
Yes |
A string that identifies the record to operate on. The In argument can contain the name of the table, a select query, or a SQL statement.
|
||
|
Where Condition |
No |
A string expression used to restrict the range of data on which the LookupRecord data block is performed. For example, criteria are often equivalent to the WHERE clause in an SQL expression, without the word WHERE. If criteria are omitted, the LookupRecord data block operates on the entire domain specified by the In argument. Any field that is included in criteria must also be a field in In. |
||
|
Alias |
No |
A string that provides an alternative name for the record specified by the In argument. Often used to shorten the table name for subsequent references to prevent possible ambiguous references. If Alias is not specified, the table or query name will be used as the alias. |
The following example shows how to use the SetReturnVar action to return a value from a named data macro. A ReturnVar named CurrentServiceRequest is returned to the macro or Visual Basic for Applications (VBA) subroutine that called the named data macro.
Sample code provided by: The Microsoft Access 2010 Programmer’s Reference
RunDataMacro
Macro Name tblServiceRequests.dmGetCurrentServiceRequest
Parameters
prmAssignedTo =[ID]
SetProperty
Control Name txtCurrentSR
Property Value
Value =[ReturnVars]![CurrentServiceRequest]
The following example shows how to use the RaiseError action to cancel the Before Change data macro event. When the AssignedTo field is updated, a LookupRecord data block is used to determine whether the assigned technician is currently assigned to an open service request. If this is true, the Before Change event is cancelled and the record is not updated.
/* Get the name of the technician */
Look Up A Record In tblTechnicians
Where Condition =[tblTechnicians].[ID]=[tblServiceRequests].[AssignedTo]
SetLocalVar
Name TechName
Expression [tblTechnicians].[FirstName] & " " & [tblTechnicians].[LastName]
/* End LookUpRecord */
If Updated("AssignedTo") Then
Look Up A Record In tblServiceRequests
Where Condition SR.[AssignedTo]=tblServiceRequests[AssignedTo] And
SR.[ID]<>tblServiceRequests.[ID] And IsNull(SR.[ActualCompletionDate])
Alias SR
RaiseError
Error Number 1234
Error Description ="Cannot assign a request to the specified technician: " & [TechName]
End If
Note