What I should do in such a case: write a separate module (either a VBA module or an Access macro) and call that from the click event of both command buttons. The code contained in a form can use local variables defined in the form (which aren't available in the other form), so a direct call from one form to. Dec 12, 2011 Tips and Information for people wanting to explore the Microsoft Access Database. Thursday, 15 December 2011. Enable and Disable a Form Control using VBA. Jul 07, 2010 Bringing an open Access form in the background. Activate event if MyForm is not the active form. An open Access form in the background to the front. The command button was located on a Customer Details form which had an Orders Subform in the lower section. The reason I wanted to Enable or Disable the Command Button (located on the parent form), was that it was used to Delete the selected record highlighted in the Orders Subform's datasheet. I needed to get the Delete Button to enforce the business rule whereby once an order has been confirmed, it should not be deleted. As such, if the user highlighted a confirmed order in the subform, the Delete button is dynamically disabled, and vice versa. As you can see, I have used an Statement to determine whether or not the Order has been confirmed. In order to create the conditional expression, I used the IsNull and functions together to see if the OrderConfirmed field of tblOrders contained a date. ![]() ![]() The IsNull function returns a boolean value, True or False, to indicate whether its parameter (in this case the result of a DLookUp function) is or is not null; and the DLookUp function, looks up the value contained in the OrderConfirmed field of tblOrders where OrderId matches that of the current record displayed on the Orders subform. Form Events The Event we are going to concentrate on for this tip are Form Events and, in particular, the events that occur when a form is opened. A ‘Form Event’ is an Event that can occur within a form. Events occur for forms when you open or close a form, move between forms, or work with data on a form. An easy way to view the available Events for a Form (Control or Report) is to open the properties window of the Form in question. To do this right click in the upper left hand corner of the form, where the two rulers meet, and select ‘Properties’ (left click) from the list displayed. With Events, it is important to remember that they occur in order and the attachment of your code to a particular event will set when that code is run. Sometimes it can be a bit of trial and error to determine where the best position is to place your Macro or Code. If you open a Form, the following Events occur in the following order: • Open • Load • Resize • Activate • (GotFocus) • Current If there is no active Control on a Form, the GotFocus event will occur. If there is an Active Control, the GotFocus Event will not occur. This is because the Focus is on the form rather than a Control, and therefore this Event can occur if the focus is not on an on object within the form. Open Form Events On Open Event The Open Event occurs when a form is opened, but before the first record is displayed. ![]() Therefore, attach code here that you wish to run as soon as the form is opened. The Open event will not occur when you activate (move to a previously opened form), i.e. If you open a second form from the first form, then close the second form, the first form’s On Open Event will not occur as the first form has not been closed and re-opened, it has just been hidden behind the second form. If the Form is based on a Query, the Query is run prior to the On Open Event. On Load Event Whereas the on Open Event occurs when the form is opened and before the first record is displayed, the On Load Event occurs when the first record is displayed. On Resize Event The Resize Event occurs when a form is opened or whenever the form’s size changes. On Activate Event The Activate Event occurs when a form receives the focus and becomes the active window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
May 2018
Categories |