| | Product Information Help and How-to Training Templates Support and Feedback Technical Resources Additional Resources | Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.
Set the value of a property in response to an event
You can assign the value of a property in response to an event (event: An action recognized by an object, such as a mouse click or key press, for which you can define a response. An event can be caused by a user action or a Visual Basic statement, or it can be triggered by the system.), such as a click on a command button, by adding a SetValue action to a macro (macro: An action or set of actions that you can use to automate tasks.) or by using an assignment statement (statement: A syntactically complete unit that expresses one specific kind of operation, declaration, or definition. A statement is usually on one line in a procedure or Declarations section, but two or more can be on a line separated by a colon (:).) in a Microsoft Visual Basic (Microsoft Visual Basic: A high-level, visual-programming version of Basic. Visual Basic was developed by Microsoft for building Windows-based applications.) procedure. Use a macro
- To create a macro, click Macros
under Objects, and then click the New button on the Database window toolbar.
- In a blank action row, click SetValue in the action list (action list: The list that appears when you click the arrow in the Action column of the Macro window.).
- Set the Item argument to the identifier (identifier (expressions): An element of an expression that refers to the value of a field, control, or property. For example, Forms![Orders]![OrderID] is an identifier that refers to the value in the OrderID control on the Orders form.) for the property whose value you want to set, and then set the Expression argument to the value you want to assign to the property.
- Click Save
to save the macro.
- Go to the form or report, open the property sheet for the object whose event will run the macro, and set the event property (event property: A named attribute of a control, form, report, data access page, or section you use to respond to an associated event. You can run a procedure or macro when an event occurs by setting the related event property.) to the name of the macro.
Use Visual Basic code
- To open the event procedure for the appropriate event, open the form in Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.).
- Display the property sheet for the form and then click the Event tab.
- Click the event property for the event that you want to trigger the procedure.
For example, to respond to a mouse click on a command button, open the button's OnClick event procedure.
- Click Build
next to the property box to display the Choose Builder dialog box.
- Double-click Code Builder to display the event procedure window
- Add an assignment statement to the procedure by typing the identifier (identifier (expressions): An element of an expression that refers to the value of a field, control, or property. For example, Forms![Orders]![OrderID] is an identifier that refers to the value in the OrderID control on the Orders form.) for the property whose value you want to set, an equal sign (=), and the value you want to assign.
- Do one of the following:
To refer to the property of a control (control: A graphical user interface object, such as a text box, check box, scroll bar, or command button, that lets users control the program. You use controls to display data or choices, perform an action, or make the user interface easier to read.) on the current form, type the Me keyword followed by the ! operator, the name of the control, the . (dot) operator, and the name of the property. For example, the following statement assigns the value False to the Visible property of the DateDue control on the current form:
Me![DateDue].Visible = False
To refer to the property of a control on a different form, type the control's full identifier. For example, the following identifier refers to the Visible property of the DateDue control on the ShipForm form:
Forms![ShipForm]![DateDue].Visible
|