473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code returns unexpected Null for Listbox Column

I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub
Nov 12 '05 #1
7 7057
Am Tue, 13 Apr 2004 09:16:33 -0700 schrieb Douglas Buchanan:
I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub


Hello,

are the columns 3 and 4 in your Listbox empty,
if they do so they are really NULL.

You can't use NULL with a string-function.
To avoid this error, check with the "ISNULL" function.

HTH
Karpi
<fluctuat nec mergitur>
Nov 12 '05 #2
Hi Douglas,

I think you need to assign a variable of type Variant in order to accomodate
Null values.
(Message boxes will come up empty if the field is null, but this code should
run without errors.)

Try the code below, which is just a modified version of the help example
from the "ItemsSelec ted" topic.

Note that you can use Debug.Print (as I have commented out below) to view
all of the results in the debug window at once instead of multiple message
boxes.
=============== =============== =========
Private Sub lstPrv_DblClick (Cancel As Integer)
Dim ctl As Control
Dim varItm As Variant, intI As Integer

Set ctl = Me.lstPrv

For Each varItm In ctl.ItemsSelect ed
For intI = 0 To ctl.ColumnCount - 1
'Debug.Print ctl.Column(intI , varItm)
MsgBox ctl.Column(intI , varItm)
Next intI
Next varItm

Set ctl = Nothing

End Sub
=============== =============== =========
HTH,
Don
Douglas Buchanan <db*********@co mcast.net> wrote in message
news:db******** *************** **@posting.goog le.com...
I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub

Nov 12 '05 #3
Hans
are the columns 3 and 4 in your Listbox empty,
if they do so they are really NULL.
No, colums 3 and 4 are not empty! That is why I am so mystified.
In fact every row dispalys all columns. In fact the reason these
records *are displayed* is because those values are present.

I can see the values but I cannot reach them with code! Does anyone
have an explaination for that?

Douglas

Hans-Joerg Karpenstein <hj***********@ web.de> wrote in message news:<pa******* *************** ******@web.de>. .. Am Tue, 13 Apr 2004 09:16:33 -0700 schrieb Douglas Buchanan:
I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub


Hello,

are the columns 3 and 4 in your Listbox empty,
if they do so they are really NULL.

You can't use NULL with a string-function.
To avoid this error, check with the "ISNULL" function.

HTH
Karpi
<fluctuat nec mergitur>

Nov 12 '05 #4
Don,

Your code works, but what's wrong with this code?

Private Sub lstPrv_DblClick (Cancel As Integer)
MsgBox Me.lstPrv.Colum n(3)
End Sub

I've never before had to create an object and use a set statement to
access a column value in the past. What's so special this time?

There are *no* null values in the list box! The presence of columns 3
and 4 are part of queries where statement - they display in the list
box - they aren't null.

What is wrong with "MsgBox Me.lstPrv.Colum n(3)"?

Am I missing something?

Douglas

"Don Leverton" <My*****@Telus. Net> wrote in message news:<q%Zec.265 $aD.12@edtnps89 >...
Hi Douglas,

I think you need to assign a variable of type Variant in order to accomodate
Null values.
(Message boxes will come up empty if the field is null, but this code should
run without errors.)

Try the code below, which is just a modified version of the help example
from the "ItemsSelec ted" topic.

Note that you can use Debug.Print (as I have commented out below) to view
all of the results in the debug window at once instead of multiple message
boxes.
=============== =============== =========
Private Sub lstPrv_DblClick (Cancel As Integer)
Dim ctl As Control
Dim varItm As Variant, intI As Integer

Set ctl = Me.lstPrv

For Each varItm In ctl.ItemsSelect ed
For intI = 0 To ctl.ColumnCount - 1
'Debug.Print ctl.Column(intI , varItm)
MsgBox ctl.Column(intI , varItm)
Next intI
Next varItm

Set ctl = Nothing

End Sub
=============== =============== =========
HTH,
Don
Douglas Buchanan <db*********@co mcast.net> wrote in message
news:db******** *************** **@posting.goog le.com...
I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub

Nov 12 '05 #5
Am Tue, 13 Apr 2004 21:14:13 -0700 schrieb Douglas Buchanan:

Hi,

the column property has an optional parameter row.
Maybe you have to use this parameter.
Also check in the help for the selected property.

HTH
Karpi
<fluctuat nec mergitur>
Hans
are the columns 3 and 4 in your Listbox empty,
if they do so they are really NULL.


No, colums 3 and 4 are not empty! That is why I am so mystified.
In fact every row dispalys all columns. In fact the reason these
records *are displayed* is because those values are present.

I can see the values but I cannot reach them with code! Does anyone
have an explaination for that?

Douglas

Hans-Joerg Karpenstein <hj***********@ web.de> wrote in message news:<pa******* *************** ******@web.de>. ..
Am Tue, 13 Apr 2004 09:16:33 -0700 schrieb Douglas Buchanan:
> I cannot access certain column values of a list box using code.
>
> I have a list box 'lstPrv' populated by the query below.
>
> SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
> lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
> lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD
>
> These are the columns displayed
> tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
> lkpSrv.pkSrvID
>
> Selected properties of the list box;
> ColumnCount = 5
> ColumnWidths = 1;1;1;1;1;
>
> The list box displays correctly.
>
> Why do lines indicated in the following error when executed?
>
> "Run-time error '94':
> Invalid use of Null"
>
> Test code:
>
> Private Sub lstPrv_DblClick (Cancel As Integer)
> 'MsgBox Me.lstPrv.Colum n(0)
> 'MsgBox Me.lstPrv.Colum n(1)
> 'MsgBox Me.lstPrv.Colum n(2)
> 'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
> MsgBox Me.lstPrv.Colum n(4) << Results in Null error
>
> End Sub


Hello,

are the columns 3 and 4 in your Listbox empty,
if they do so they are really NULL.

You can't use NULL with a string-function.
To avoid this error, check with the "ISNULL" function.

HTH
Karpi
<fluctuat nec mergitur>


Nov 12 '05 #6
db*********@com cast.net (Douglas Buchanan) wrote in
news:db******** *************** **@posting.goog le.com:
I cannot access certain column values of a list box using code.

I have a list box 'lstPrv' populated by the query below.

SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID =
lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD

These are the columns displayed
tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
lkpSrv.pkSrvID

Selected properties of the list box;
ColumnCount = 5
ColumnWidths = 1;1;1;1;1;

The list box displays correctly.

Why do lines indicated in the following error when executed?

"Run-time error '94':
Invalid use of Null"

Test code:

Private Sub lstPrv_DblClick (Cancel As Integer)
'MsgBox Me.lstPrv.Colum n(0)
'MsgBox Me.lstPrv.Colum n(1)
'MsgBox Me.lstPrv.Colum n(2)
'MsgBox Me.lstPrv.Colum n(3) << Results in Null error
MsgBox Me.lstPrv.Colum n(4) << Results in Null error

End Sub


My recollection is:

1. all columns from list or combo boxes are either strings or nulls,
regardless of the field type which underlies them;
2. msgbox errs on trying to display a null.

So I suggest that you use some variation of the null to zero function such
as:

msgbox Nz(Me.lstPrv.Co lumn(3),"null" or "0" or "" or whatever)

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #7
Hi Douglas,

IMHO, it's kinda like the Cadbury secret. :)

Seriously, I'm no expert, but I suspect that it has to do with ambiguity.
You're asking the code to return the contents of the 4th column, but you're
not specifying from which ROW.
Using the ItemsSelected Property says "give me the contents of the selected
row" (or rows if you have a multi-select list-box setup. The code that I
gave you will also handle multi-selection, BTW.)

As far as the "Set" thing goes ... that just gives you access to all of the
control's properties and saves a whole lot of typing.
-------------------------------------------------
You *may* have been able to do it like this instead:

For Each varItm In Me.lstPrv.Items Selected
For intI = 0 To Me.lstPrv.Colum nCount - 1
'Debug.Print Me.lstPrv.Colum n(intI, varItm)
MsgBox Me.lstPrv.Colum n(intI, varItm)
Next intI
Next varItm
-------------------------------------------------
Or *maybe* even like this:

With Me.lstPrv

For Each varItm In .ItemsSelected
For intI = 0 To .ColumnCount - 1
'Debug.Print .Column(intI, varItm)
MsgBox .Column(intI, varItm)
Next intI
Next varItm

End With
-------------------------------------------------

But I do think the Set method would be the preferred method.

HTH,
Don
=============== =============== ===============

Douglas Buchanan <db*********@co mcast.net> wrote in message
news:db******** *************** **@posting.goog le.com...
Don,

Your code works, but what's wrong with this code?

Private Sub lstPrv_DblClick (Cancel As Integer)
MsgBox Me.lstPrv.Colum n(3)
End Sub

I've never before had to create an object and use a set statement to
access a column value in the past. What's so special this time?

There are *no* null values in the list box! The presence of columns 3
and 4 are part of queries where statement - they display in the list
box - they aren't null.

What is wrong with "MsgBox Me.lstPrv.Colum n(3)"?

Am I missing something?

Douglas


<Previous threads snipped>
Nov 12 '05 #8

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

Similar topics

0
1555
by: Sara | last post by:
We have a Cobol stored procedures on DB2 OS/390. We are able to access the stored procedures from a distributed platform Windows 2000/ Linux / Unix using DB2 Connect. But it does not return column names. It returns only column numbers. When we try to retrieve the metadata of resultset , it is returning NULL for column names or any other meta data from ResultSetMetaData Object. Can you please advise how to resolve this problem. Thanks...
7
1754
by: Douglas Buchanan | last post by:
I cannot access certain column values of a list box using code. I have a list box 'lstPrv' populated by the query below. SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID, lkpSrv.pkSrvID FROM (lkpCat INNER JOIN lkpSrv ON lkpCat.pkCatID = lkpSrv.fkCatID) INNER JOIN tblPrv ON lkpSrv.pkSrvID = tblPrv.fkSrvD These are the columns displayed tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,
24
12591
by: John Smith | last post by:
How to test whether strstr() returns a null pointer or not? Do I use something like the following? if(NULL != strstr(str1,str2)) That does not seem to work.
1
2060
by: tdmailbox | last post by:
I have the following regular expression. It works fine if the regex code returns a match. However if not the .match code fails. How can I code this so that it skips the match if the regular expression does not find anything? Regex reg_unit_num = new Regex("L_unit_num.*?>(.*?)</td>", RegexOptions.IgnoreCase);
3
1423
by: Felix_Jiang | last post by:
The following code returns different result when running on dotnetFramework 1.1 and 2.0. For 1.1, it returns "Object". For 2.0, it returns "String". Can anyone explain to me why? Thanks! ========================================= using System; delegate object D(); class A {
2
1348
by: Andrew | last post by:
hi, I got an error when the dataset returns a null value. eg. string a; a = (string)ds.Tables.Rows; How do I handle this error ? Thanks. regards,
1
1435
by: shrina | last post by:
Im finding it difficult to do the following: i want to create a user interface so that the user can browse and select a file and upload it. Then i want all the column names from the file to appear...in a RadioButtonList. I am finding it hard to code and display just the column names form the file in a RadioButtonList. Is there someone that can help me?
0
2091
by: diane | last post by:
Just trying to upsize using VFP 9 with SQL 2005 using VFP remote views. One in particular keeps coming up and saying Cannot insert the value NULL into column, when I really don't think I am inserting a NULL value. Oddly sometimes it works but I don't know why. Can anyone suggest anything else I can try? Perhaps this is the wrong group I'm posting to - it was just the one that came up with other errors giving the same message, but none of...
1
2689
by: Octo Siburian | last post by:
I have been collecting data from ms.access database into a class object '_Get and put in data from database Fingerprint(RAS) into CPresensiFingerprint Public Function GetdbFingerprint() As CPresensiFingerprint Dim presensiFinger As New CPresensiFingerprint Dim SQLSelectdbRAS As String Dim rsFinger As Recordset Dim dateNow_ As Date dateNow_ = um_TgldanJamSkrg()
0
9529
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
10457
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
10013
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
7550
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
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
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...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
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.