devxlogo

Implementing Interfaces on Forms

Implementing Interfaces on Forms

There is an easy way to make your application respond to data changes in forms, by implementing interfaces on your forms.For example, when you have an order application and insert, change or delete a customer, you want the customer combobox on all open order forms to be updated. Here is the code:

 'IEvent - Class modulePublic Enum AppEvents    aeCustomerInsert    aeCustomerUpdate    aeCustomerDeleted    aeOrderInsert    aeOrderUpdate    aeOrderDeletedEnd EnumPublic Function AppEvent(RaisedEvent As AppEvents, _                         Optional Value1 As Variant, _                         Optional Value2 As Variant, _                         Optional Value3 As Variant, _                         Optional Value4 As Variant, _                         Optional Value5 As Variant)End Function'frmCustomer - Customer formPrivate Sub cmdSave_Click()Dim frmForm As FormDim vEvent As IEvent    For Each frmForm In Forms        If TypeOf frmForm Is IEvent Then            Set vEvent = frmForm            vEvent.AppEvent aeCustomerUpdate        End If    NextEnd Sub'frmOrder - Order FormImplements IEventPrivate Sub Form_Load()    LoadCustomerComboEnd SubPrivate Function IEvent_AppEvent(RaisedEvent As AppEvents,                                 Optional Value1 As Variant,                                 Optional Value2 As Variant,                                 Optional Value3 As Variant,                                 Optional Value4 As Variant,                                 Optional Value5 As Variant) As Variant    Select Case RaisedEvent    Case aeCustomerInsert, aeCustomerUpdate, aeCustomerDeleted        LoadCustomerCombo    End SelectEnd Function

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist