I'm somewhat confused with your Table_2.
Is it a table where you assign an employee at certain date to certain department? When this is the case, then field department in Table_1 is not needed.
Or it is a table where you enter some unidentified info about employee at certain date? When this is the case, then is the employee attached to department in Table_1 for lifetime?!!!
Generally the database structure must be something like:
tblEmployees: EmployeeID, Forename, LastName, ...
tblDepartments: DepartmentID, DepartmentName
tblEmplDep: EmplDepID, EmplDepDate, EmployeeID, DepartmentID
tblEmplEvent: EmplEventID, EventDate, EmployeeID, EventDescription
A description of form to register events:
Form's datasource is tblEmplEvent;
The form is either single or continuous;
On form you have a text box p.e. txtEventDate, linked to field EventDate. The default value for control =Date(). NB! Don't set default value for date field - otherwise you risk to get orphan entries! You can disable/lock this control permanently, when you want to restrict date edit for user;
The next control will be a combo box, p.e. cbbEmployee, linked to field EmployeeID (Control Source = EmployeeID). Set the RowSource for combo as "SELECT EmployeeID, LastName & " " & Forename AS FullName FROM tblEmployees", BoundColumn to 1, ColumnCount to 2 and ColumnWidths to "0;2.5";
The next control will be an unbound text box, p.e. txtDepartment;
The last control will be a text box linked to field EventDescription.
For cbbEmployee, you create an OnChange event, which calculates matching department name depending on employee and event date running a query, and writes it into unbound text box (txtDepartment). The query text will be something like (on fly):
Code:
strQry =
"SELECT a.DepartmentName FROM EmplDep a
WHERE a.EmployeeID = " & Me.ccbEmployee & " AND a.EmplDepDate = " &
(SELECT TOP 1 b.EmplDepDate FROM EmplDep b WHERE EmployeeID = " & Me.ccbEmployee & " AND b.EmployeeDate <= #" & Me.txtEventDate & "# ORDER BY EmplDepDate DESC"
And same code you use in OnCurrent event of form, so the right department is displayed, whenever you select another record.