Imagine a class and two forms:
- clsEmployeeWriter: dedicated to writing employees to Employees table
- frmNewEmployee: form allowing to create a new employee
- frmEmployees: contains a listbox containing all employees
What I would like to do is create a custom event in the class that raises when an employee is added to the table. I'd like to subscribe frmEmployees to that event and update the listbox when it triggers.
This is what I've come up with so far:
clsEmployeeWriter
frmNewEmployee
frmEmployees
Can you advise what I'm doing wrong and what I still need?
- clsEmployeeWriter: dedicated to writing employees to Employees table
- frmNewEmployee: form allowing to create a new employee
- frmEmployees: contains a listbox containing all employees
What I would like to do is create a custom event in the class that raises when an employee is added to the table. I'd like to subscribe frmEmployees to that event and update the listbox when it triggers.
This is what I've come up with so far:
clsEmployeeWriter
Code:
Public Event EmployeeWritten()
Public Sub Write(Name As String)
... write code ...
RaiseEvent EmployeeWritten
End sub
frmNewEmployee
Code:
Sub
dim e as new clsEmployeeWriter
e.Write("John McClain")
End sub
frmEmployees
Code:
private WithEvents writer As clsEmployeeWriter
private sub writer_EmployeeWritten()
... Update employees listbox ...
end sub
Can you advise what I'm doing wrong and what I still need?