473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Invalid use of NULL

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 ***
Nov 13 '05 #1
5 4863
One more piece of information ...
The error only occurs if I type in data for a record that I KNOW does
not exist. If I type in data for a record that already exists (and some
of the fields are NULL on the data base and I make sure that I don't
fill in data for those fields) .. the DLOOKUP works and finds a match.

Wow ... now I'm even more stumped.

HELLLLLPPPP.

Regards,
SueB

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2
Br
Susan Bricker wrote:
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


Change ....

Dim lngID As Long

to

Dim varID as Variant

You can't set a long to NULL.
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #3
Susan Bricker <sl*****@verizon.net> wrote in news:aSx5f.38$8Q2.510
@news.uswest.net:

'Look for an identical record in the tblPeople table
lngID = DLookup("[peopleID]", _
"tblPeople", _
strCriteria)


lngID = NZ(Dlookup("[PeopleID]","[tblPeople]",strcriteria),0)

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #4
1. s works just as good for a variable name as strCriteria. Also makes
your code more readable.
2. You could eliminate all your "Not"s by flipping the conditional:

If Not IsNull(Me!fname) Then
s = s & "[fname] = '" & Me!fname & "' "
Else
s = s & "IsNull([fname]) "
End If

becomes:

If IsNull(Me!fname) Then
s = s & "IsNull([fname]) "
Else
s = s & "[fname] = '" & Me!fname & "' "
End If

Which is unnoticably faster but DOES make your code more readable.

3. IsNull() is a function. What you are actually doing is creating the
WHERE clause of an SQL query. IsNull has no meaning in SQL - so you could
just change the IsNull to Is Null.

4. Is there really a reason to do the lookup on a null middle initial, or
address, or first name? I mean, if all you're trying to do is find a match,
testing if it matches a null won't get you much. So, for instance, if the
first name Is Null, why not just leave it out of the search criteria:

If Not IsNull(Me!fname) Then
s = s & "[fname] = '" & Me!fname & "' "
End If

So now you have something like this:

Dim s As String
s = vbNullString
If Not IsNull(Me!fname) Then s = s & " AND [fname] = '" & Me!fname & "'"
If Not IsNull(Me!midinit) Then s = s & " AND [midinit] = '" & Me!midinit &
"'"
If Not IsNull(Me!lname) Then s = s & " AND [lname] = '" & Me!lname & "'"
If Not IsNull(Me!suffix) Then s = s & " AND [suffix] = '" & Me!suffix & "'"

Note that I've added " AND" to the first string, since using this structure,
any clause may be left out of the final string, including the first one.
After all the statements, you then add:

If s <> vbNullString Then
s = Mid(s, 6) ' trims the very first " AND "
.... stuff ....
Else
' No criteria entered
Endif

5. Just before the DLookup is run, while testing, place a MsgBox s line to
examine the string carefully.

As a final note, after you get it working with DLookup, consider using ADO
or DAO.

--
Darryl Kerkeslager

Nov 13 '05 #5
And of course, missed the trees through the forest!

--
Darryl Kerkeslager

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
1
by: Patrick Dunnigan | last post by:
Hi, I am attempting a bulk copy from a c program into SQL Server 2000 using DBLib in freeTDS 0.63 RC11 (gcc 3.4.3, RH 9). I am getting an error message that I cannot find any documentation on. ...
2
by: headware | last post by:
I'm getting a weird problem in an Access query. I have a table that contains a field calle F1 that's a 2 character text field. The first character is always a number. What I'd like to do is find...
3
by: Frank Perry | last post by:
Howdy, I'm trying to write data out the com port. I have taken the code from the sample on the MSDN Library CD and used the parts that seem relevant. I can open the com port with CreateFile...
0
by: Jerry | last post by:
Below is ALL the code for all the databases... Here's the problem: I callup the aspx file in IE and the form comes up just fine. When I select a person to update, I get the subject error. ...
15
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed...
9
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating...
6
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
3
by: rando1000 | last post by:
I'm pulling data from a field on a form, evaluating whether or not it's null, then calculating based on the data in the field. Here's my code for evaluating the field: intAdvanced = IIf(Not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.