'Create String variables to hold DCount test condition string arguments
Dim wFullID As String, wDoBNameSSN As String, wDoBSSN As String, wDoBFullName As String, wDoBName As String, wSSNName As String, wSSN As String, wDoB As String, wFullName As String
'Set string SQL arguments to pass to DCount criteria
Debug.Print "***DCOUNT CRITERIA STRINGS***"
wFullID = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "# AND [client_4SSN]='" & [Forms]![frm_Clients]![client_4SSN] & "' AND [client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' AND [client_FName]='" & [Forms]![frm_Clients]![client_Fname] & "'"
Debug.Print "Full ID test --> " & wFullID
wDoBNameSSN = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "# AND [client_4SSN]='" & [Forms]![frm_Clients]![client_4SSN] & "' AND ([client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' OR [client_FName]='" & [Forms]![frm_Clients]![client_Fname] & "')"
Debug.Print "First OR Last/SSN/DoB test --> " & wDoBNameSSN
wDoBSSN = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "# AND [client_4SSN]='" & [Forms]![frm_Clients]![client_4SSN] & "'"
Debug.Print "DoB/SSN test --> " & wDoBSSN
wDoBFullName = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "# AND [client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' AND [client_FName]='" & [Forms]![frm_Clients]![client_Fname] & "'"
Debug.Print "DoB/Full Name test --> " & wDoBFullName
wDoBName = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "# AND ([client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' OR [client_FName]='" & [Forms]![frm_Clients]![client_Fname] & "')"
Debug.Print "DoB/Name test --> " & wDoBName
wSSNName = "[client_4SSN]='" & [Forms]![frm_Clients]![client_4SSN] & "' AND ([client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' OR [client_Fname]='" & [Forms]![frm_Clients]![client_Fname] & "')"
Debug.Print "First OR Last/SSN test --> " & wSSNName
wSSN = "[client_4SSN]='" & [Forms]![frm_Clients]![client_4SSN] & "'"
Debug.Print "SSN test --> " & wSSN
wDoB = "[client_DoB]=#" & [Forms]![frm_Clients]![client_DoB] & "#"
Debug.Print "DoB test --> " & wDoB
wFullName = "[client_Lname]='" & [Forms]![frm_Clients]![client_Lname] & "' AND [client_Fname]='" & [Forms]![frm_Clients]![client_Fname] & "'"
Debug.Print "Full name test --> " & wFullName
'Run DCount tests using created string variables, from most stringent to least,
'Proceed accordingly to either discard/delete or save actions
If (DCount("[client_ID]", "[qry_Clients]", wFullID)) > 0 Then '@ least one record found with a complete identical match of all ID fields
Dim FullMatchfound As Integer
FullMatchfound = MsgBox("A client with an identical combination of name, date of birth, and partial SSN already exists in the system.", vbOKOnly, "WARNING: DUPLICATE FOUND!")
GoTo DeleteRoutine
ElseIf (DCount("[client_ID]", "[qry_Clients]", wDoBNameSSN)) > 0 Then '@ least one record found with identical DoB, first or last name, and SSN
Dim DoBNameSSNFound As Integer
DoBNameSSNFound = MsgBox("A client with an identical combination of first or last name, date of birth, and partial SSN already exists in the system.", vbOKOnly, "WARNING: DUPLICATE FOUND!")
GoTo DeleteRoutine
ElseIf (DCount("[client_ID]", "[qry_Clients]", wDoBSSN)) > 0 Then 'at least one record found with identical DoB and partial SSN
Dim DoBSSNFound As Integer
DoBSSNFound = MsgBox("A client with an identical date of birth and partial SSN already exists in the system.", vbOKOnly, "WARNING: DUPLICATE FOUND!")
GoTo DeleteRoutine
ElseIf (DCount("[client_ID]", "[qry_Clients]", wDoBFullName)) > 0 Then 'at least one record found with identical first/last and DoB.
Dim DoBFullNameFound As Integer
DoBFullNameFound = MsgBox("A client with an identical date of birth and full name already exists in the system.", vbOKOnly, "WARNING: DUPLICATE FOUND!")
GoTo DeleteRoutine
ElseIf (DCount("[client_ID]", "[qry_Clients]", wDoBName)) > 0 Then 'at least one record found with identical DoB and first or last name
Dim DoBNameFound As Integer
DoBNameFound = MsgBox("A client with an identical date of birth and first or last name already exists in the system." & vbCrLf & "Are you certain this client is not a duplicate entry?", vbYesNo, "WARNING: POSSIBLE DULPICATE!")
If DoBNameFound = vbYes Then
Dim DoBNameFoundConfirm As Integer
DoBNameFoundConfirm = MsgBox("Duplicate client records may result in eventual deletion, replication, or missing data. " & vbCrLf & "Are you ABSOLUTELY SURE you want to save this client record?", vbYesNo, "WARNING: POSSIBLE DUPLICATE!")
If DoBNameFoundConfirm = vbYes Then
GoTo SaveRoutine
Else
GoTo DeleteRoutine
End If
Else
GoTo DeleteRoutine
End If
ElseIf (DCount("[client_ID]", "[qry_Clients]", wSSNName)) > 0 Then '@ least one record found with identical partial SSN and first or last name
Dim SSNNameFound As Integer
SSNNameFound = MsgBox("A client with an identical partial SSN and first or last name already exists in the system." & vbCrLf & "Are you certain this client is not a duplicate entry?", vbYesNo, "WARNING: POSSIBLE DULPICATE!")
If SSNNameFound = vbYes Then
Dim SSNNameFoundConfirm As Integer
SSNNameFoundConfirm = MsgBox("Duplicate client records may result in eventual deletion, replication, or missing data. " & vbCrLf & "Are you ABSOLUTELY SURE you want to save this client record?", vbYesNo, "WARNING: POSSIBLE DUPLICATE!")
If SSNNameFoundConfirm = vbYes Then
GoTo SaveRoutine
Else
GoTo DeleteRoutine
End If
Else
GoTo DeleteRoutine
End If
ElseIf (DCount("[client_ID]", "[qry_Clients]", wSSN)) > 0 Then '@ least one record found with identical partial SSN
Dim SSNFound As Integer
SSNFound = MsgBox("A client with an identical partial SSN already exists in the system." & vbCrLf & "Are you certain this client is not a duplicate entry?", vbYesNo, "WARNING: POSSIBLE DULPICATE!")
If SSNFound = vbYes Then
Dim SSNFoundConfirm As Integer
SSNFoundConfirm = MsgBox("Duplicate client records may result in eventual deletion, replication, or missing data. " & vbCrLf & "Are you ABSOLUTELY SURE you want to save this client record?", vbYesNo, "WARNING: POSSIBLE DUPLICATE!")
If SSNFoundConfirm = vbYes Then
GoTo SaveRoutine
Else
GoTo DeleteRoutine
End If
Else
GoTo DeleteRoutine
End If
ElseIf (DCount("[client_ID]", "[qry_Clients]", wDoB)) > 0 Then '@ least one record found with identical DoB
Dim DoBFound As Integer
DoBFound = MsgBox("A client with an identical date of birth already exists in the system." & vbCrLf & "Are you certain this client is not a duplicate entry and should be saved?", vbYesNo, "WARNING: POSSIBLE DUPLICATE!")
If DoBFound = vbYes Then
GoTo SaveRoutine
Else
GoTo DeleteRoutine
End If
ElseIf (DCount("[client_ID]", "[qry_Clients]", wFullName)) > 0 Then '@ least one record found with identical first & last name
Dim FullNameFound As Integer
FullNameFound = MsgBox("A client with an identical full name already exists in the system." & vbCrLf & "Are you certain this client is not a duplicate entry and should be saved?", vbYesNo, "WARNING: POSSIBLE DUPLICATE!")
If FullNameFound = vbYes Then
GoTo SaveRoutine
Else
GoTo DeleteRoutine
End If
Else 'no identifying field combinations were found that indicate a possible duplicate
GoTo SaveRoutine
End If