473,385 Members | 1,409 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,385 software developers and data experts.

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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(4) << Results in Null error

End Sub
Nov 12 '05 #1
7 7024
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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(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 "ItemsSelected" 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.ItemsSelected
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*********@comcast.net> wrote in message
news:db*************************@posting.google.co m...
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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(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.Column(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.Column(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 "ItemsSelected" 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.ItemsSelected
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*********@comcast.net> wrote in message
news:db*************************@posting.google.co m...
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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(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.Column(0)
> 'MsgBox Me.lstPrv.Column(1)
> 'MsgBox Me.lstPrv.Column(2)
> 'MsgBox Me.lstPrv.Column(3) << Results in Null error
> MsgBox Me.lstPrv.Column(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*********@comcast.net (Douglas Buchanan) wrote in
news:db*************************@posting.google.co m:
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.Column(0)
'MsgBox Me.lstPrv.Column(1)
'MsgBox Me.lstPrv.Column(2)
'MsgBox Me.lstPrv.Column(3) << Results in Null error
MsgBox Me.lstPrv.Column(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.Column(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.ItemsSelected
For intI = 0 To Me.lstPrv.ColumnCount - 1
'Debug.Print Me.lstPrv.Column(intI, varItm)
MsgBox Me.lstPrv.Column(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*********@comcast.net> wrote in message
news:db*************************@posting.google.co m...
Don,

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

Private Sub lstPrv_DblClick(Cancel As Integer)
MsgBox Me.lstPrv.Column(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.Column(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
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...
7
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,...
24
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
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...
3
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! ...
2
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
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...
0
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.