Try this.
It replaces the entire code behind the form.
Edit: found a bug. See red code at bottom.
Code:
Option Compare Database
Option Explicit
Private Sub WT_Quality_Click()
Dim Quality As String
Quality = DLookup("[Name]", "[TeamWork]", "[Department]= 'Quality'")
If Me.WT_Quality = -1 And Len(Me.TeamWorktxt & vbNullString) = 0 Then
Me.TeamWorktxt = Quality
ElseIf Me.WT_Quality = -1 And Me.TeamWorktxt <> "" Then
Me.TeamWorktxt = Me.TeamWorktxt & vbCrLf & Quality
End If
If Me.WT_Quality = 0 Then
If InStr(Me.TeamWorktxt, vbCrLf & Quality) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, vbCrLf & Quality, "")
ElseIf InStr(Me.TeamWorktxt, Quality) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, Quality, "")
End If
Call Blankit
End If
End Sub
Private Sub WT_Process_Click()
Dim Process As String
Process = DLookup("[Name]", "[TeamWork]", "[Department]= 'Process'")
If Me.WT_Process = -1 And Len(Me.TeamWorktxt & vbNullString) = 0 Then
Me.TeamWorktxt = Process
ElseIf Me.WT_Process = -1 And Me.TeamWorktxt <> "" Then
Me.TeamWorktxt = Me.TeamWorktxt & vbCrLf & Process
End If
If Me.WT_Process = 0 Then
If InStr(Me.TeamWorktxt, vbCrLf & Process) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, vbCrLf & Process, "")
ElseIf InStr(Me.TeamWorktxt, Process) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, Process, "")
End If
Call Blankit
End If
End Sub
Private Sub WT_Production_Click()
Dim Production As String
Production = DLookup("[Name]", "[TeamWork]", "[Department]= 'Production'")
If Me.WT_Production = -1 And Len(Me.TeamWorktxt & vbNullString) = 0 Then
Me.TeamWorktxt = Production
ElseIf Me.WT_Production = -1 And Me.TeamWorktxt <> "" Then
Me.TeamWorktxt = Me.TeamWorktxt & vbCrLf & Production
End If
If Me.WT_Production = 0 Then
If InStr(Me.TeamWorktxt, vbCrLf & Production) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, vbCrLf & Production, "")
ElseIf InStr(Me.TeamWorktxt, Production) > 0 Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, Production, "")
End If
Call Blankit
End If
End Sub
Private Sub Blankit()
If WT_Production = 0 And WT_Quality = 0 And WT_Process = 0 Then
Me.TeamWorktxt = ""
End If
If Left(Me.TeamWorktxt, 2) = vbCrLf Then
Me.TeamWorktxt = Replace(Me.TeamWorktxt, vbCrLf, "", 1, 1)
End If
End Sub