Reputation: 313
I am working on a personnel accountability system, and I have a question about getting a field to display a value based on a value in another table that is a sub-report of the same form.
For instance, I have a tabbed interface, and the first tab is a snapshot of the person, vital data and such. I have a tab that lists retention information. The tab has a sub-report that links to another table that stores all of the flags (adverse actions) for employees. These two tables are linked together with a relationship, linking each flag to an individual employee.
I would like to have a field on the first tab titled FlagSnapshot
display either a value of Flagged
or Not Flagged
based on the value of the field FlagStatus
from the other table. The field FlagStatus
form the other table has possible values of Active
, Removed
, and Permanent
. So again, if value in field FlagStatus
in table Flags
equals Active
, I would like the FlagSnapshot
field in table Personnel
to display Flagged
. I also need to set conditions so that if the field FlagStatus
in table Flags
has the value of Removed
, then I need the field FlagSnapshot
to display the value of Not Flagged
. There are a few other values too in field FlagStatus
, but only two values in the field FlagSnapshot
.
Also, it is possible for one employee to have multiple flags, and I need to make sure that all of them are taken into account. If the table Flags
has two or three flags for the same employee and one of them reads Removed
and the other reads Active
, I need the flag snapshot field to display a value of Flagged
.
I apologize in advance for the long explanation. Also, this is not homework, it's a project I am working on at work to make things more easily tracked.
Upvotes: 2
Views: 129
Reputation: 2205
I would go with a mix of VBA and SQL, assuming you have normalized data structure (at least partially). For example, I would expect to have table FlagStatus to be a separate table and linked to other tables.
Step 1: Add Column Priority to the FlagStatus table that lists ALL FlagStatuses:
Step 2: Create a query (GetFlagStatusQuery) that returns FlagStatus with highest priority for a particular Employee:
Step 3: Create a function that returns the desired FlagStatus representation. Something like this:
Function GetFlagStatus(employeeId As Long) As String
Dim rs As Recordset
Dim qdf As QueryDef
FlagStatus = ""
Set qdf = CurrentDb.QueryDefs("GetFlagStatusQuery")
qdf.Parameters("EmployeeId_parameter") = employeeId
Set rs = qdf.OpenRecordset()
If rs.RecordCount > 0 Then
Select Case rs("FlagStatus")
Case "Active"
FlagStatus = "Flagged"
Case "Removed"
FlagStatus = "Not Flagged"
End Select
End If
End Function
Step 4: Use the GetFlagStatus function in your form/tab and pass EmployeeId parameter from the Form. For example, for a textbox control the source would be: =GetFlagStatus([EmployeeId])
Upvotes: 1