Hi. I'm back again with another brain-buster (for me). I am getting
"Invalid use of Null" with an error number of 94 for the following ...
1. Form based on a table (tblPeople)
2. The people record contains name (firstname, lastname, middle initial,
name suffix) fields, address fields (addressline1, addressline2, city,
state, zipcode, country), and some other fields (email address, phone
number, various on/off switches to indicate category to which this
person belongs)
3. The tblPeople record has PK (long int) called peopleID
4. I added some rudimentary duplicate detection logic and that is what
is failing. I build a criteria phrase and move it to a variable call
strCriteria and use the criteria in a DLOOKUP call. If the all the
fields match then we have a duplicate record.
Here's the code ... it fails at the DLOOKUP when we have a field that is
NULL.
Anybody have a better solution?
Public Function DupDetect() As Integer
'*===========================*
'Returned data ... *
'1 = Duplicate Record *
'0 = NOT a Duplicate Record *
'*===========================*
On Error GoTo Err_DupDetect
Dim lngID As Long
Dim strCriteria As String
strCriteria = ""
'Setup the CRITERIA for the DLOOKUP
If Not IsNull(Me!fname) Then
strCriteria = strCriteria & "[fname] = '" & Me!fname & "' "
Else
strCriteria = strCriteria & "IsNull([fname]) "
End If
If Not IsNull(Me!midinit) Then
strCriteria = strCriteria & "AND [midinit] = '" & Me!midinit &
"' "
Else
strCriteria = strCriteria & "AND IsNull([midinit]) "
End If
If Not IsNull(Me!lname) Then
strCriteria = strCriteria & "AND [lname] = '" & Me!lname & "' "
Else
strCriteria = strCriteria & "AND IsNull([lname]) "
End If
If Not IsNull(Me!suffix) Then
strCriteria = strCriteria & "AND [suffix] = '" & Me!suffix & "'
"
Else
strCriteria = strCriteria & "AND IsNull([suffix]) "
End If
If Not IsNull(Me!addr1) Then
strCriteria = strCriteria & "AND [addr1] = '" & Me!addr1 & "' "
Else
strCriteria = strCriteria & "AND IsNull([addr1]) "
End If
If Not IsNull(Me!addr2) Then
strCriteria = strCriteria & "AND [addr2] = '" & Me!addr2 & "' "
Else
strCriteria = strCriteria & "AND IsNull([addr2]) "
End If
If Not IsNull(Me!city) Then
strCriteria = strCriteria & "AND [city] = '" & Me!city & "' "
Else
strCriteria = strCriteria & "AND IsNull([city]) "
End If
If Not IsNull(Me!state) Then
strCriteria = strCriteria & "AND [state] = '" & Me!state & "' "
Else
strCriteria = strCriteria & "AND IsNull([state]) "
End If
If Not IsNull(Me!zipcode) Then
strCriteria = strCriteria & "AND [zipcode] = '" & Me!zipcode &
"' "
Else
strCriteria = strCriteria & "AND IsNull([zipcode]) "
End If
'Remove leading and trailing spaces
strCriteria = Trim(strCriteria)
'Look for an identical record in the tblPeople table
lngID = DLookup("[peopleID]", _
"tblPeople", _
strCriteria)
'If lngID is a valid integer then we found a record ... DUPLICATE
'Otherwise ... NODUPLICATE
If Nz(lngID, 0) > 0 Then
DupDetect = YESDUP
Else
DupDetect = NODUP
End If
Exit_DupDetect:
Exit Function
Err_DupDetect:
MsgBox strCriteria
Call ShowError("frmPeople", "DupDetect", Err.Number,
Err.Description)
Resume Exit_DupDetect
End Function
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***