473,804 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!midin it) 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!suffi x) 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!zipco de) Then
strCriteria = strCriteria & "AND [zipcode] = '" & Me!zipcode &
"' "
Else
strCriteria = strCriteria & "AND IsNull([zipcode]) "
End If

'Remove leading and trailing spaces
strCriteria = Trim(strCriteri a)

'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("frmP eople", "DupDetect" , Err.Number,
Err.Description )
Resume Exit_DupDetect

End Function

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
5 4892
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!midin it) 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!suffi x) 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!zipco de) Then
strCriteria = strCriteria & "AND [zipcode] = '" & Me!zipcode &
"' "
Else
strCriteria = strCriteria & "AND IsNull([zipcode]) "
End If

'Remove leading and trailing spaces
strCriteria = Trim(strCriteri a)

'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("frmP eople", "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*****@verizo n.net> wrote in news:aSx5f.38$8 Q2.510
@news.uswest.ne t:

'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!midin it) Then s = s & " AND [midinit] = '" & Me!midinit &
"'"
If Not IsNull(Me!lname ) Then s = s & " AND [lname] = '" & Me!lname & "'"
If Not IsNull(Me!suffi x) 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
4379
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 errors occur. In function `LRESULT WndProc(HWND__*, unsigned int, unsigned int, long int)': line 48: error: invalid conversion from `void*' to `HBRUSH__*' line 49: error: invalid conversion from `void*' to `HPEN__*'
1
6384
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. The server is sending back the following: "Received invalid row length 2 from bcp client. Minimum row size is 4." I know the row is longer 2 bytes (see below). Once this happened I created a
2
17364
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 all the records in which F1 has an even number in the first position. I first tried this: SELECT F1 FROM Table1 WHERE Nz(F1, '') <> '' AND (CInt(Left(F1, 1)) Mod 2 = 0)
3
5289
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 and get a valid file handle back. But when I try to write to it, the WriteFile comes back and tells me the handle is invalid. The program has control of the port because using Hyperterminal, I can't connect when the program is connected. There...
0
683
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. Aparently, when I select a person, it's not selecting anyone and returning this error. Here's the full error: Description: An unhandled exception occurred during the execution of the
15
2260
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 spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has a backoffice system that takes an excel spreadsheet from the
9
4931
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 a static machinekey in the machine.config and that did not help. I believe that issue only occurred when there was an inconsistent viewstate error. The error I am faced with consistently occurs. Are there any known problems with the ViewState...
6
3025
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 across a problem I can't really explain: When deleting an object from an IStorage, the space it used up will not be freed, but rather marked as unused and overwritten the next time you add an object to the storage. This is obviously working as...
0
6551
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 /new_file/prob1.rec started. Please wait.... In while loop of request searching *** glibc detected *** ./a.out: free(): invalid next size (normal): 0x099da890 *** ======= Backtrace: ========= /lib/libc.so.6
3
1809
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 IsNull(Me.txtAdvanced), CLng(Me.txtAdvanced), 0) So if the field's not null, it Converts it to a Long and sets the variable to that, otherwise, the variable is 0. However, the program's erroring on this line, Run-Time 94, invalid use of Null! How...
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.