There are two primary ways you can write VBA code for a window field object: using a window field event procedure, and referencing the window field in procedures throughout your project.
A window field event lets you execute VBA code when the user moves to, changes or moves out of a specific field. This is useful when you want to perform actions based on entries made in the field. The following section, Using window field events, explains window field events in more detail.
To reference a window’s fields, the field must be an object in your project, and the field’s window must be open (the window’s IsLoaded property is True).
If the field you’re referencing is not in the current window, you must reference the field using a qualified field name. A qualified name explicitly specifies the location of the field you’re referencing. In the following example, an event procedure for a VBA user form opens the Invoice Batch Entry window, then clicks a lookup button using the lookup button field’s qualified name:
Private Sub CommandButton1_Click() 'Open the batch entry window InvoiceBatchEntry.Open 'Click the lookup button to display the lookup InvoiceBatchEntry.LookupButton1 = 1 UserForm1.Hide End Sub