Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Apr 24, 2001

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 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
Andreas Hillqvist
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap