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

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: