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 module
Public Enum AppEvents
aeCustomerInsert
aeCustomerUpdate
aeCustomerDeleted
aeOrderInsert
aeOrderUpdate
aeOrderDeleted
End Enum
Public 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 form
Private Sub cmdSave_Click()
Dim frmForm As Form
Dim vEvent As IEvent
For Each frmForm In Forms
If TypeOf frmForm Is IEvent Then
Set vEvent = frmForm
vEvent.AppEvent aeCustomerUpdate
End If
Next
End Sub
'frmOrder - Order Form
Implements IEvent
Private Sub Form_Load()
LoadCustomerCombo
End Sub
Private 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 Select
End Function