473,387 Members | 1,501 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.

ListBox.ListCount property problem

Puzzled!
I have a list box, and I want code to behave in a particular way according to whether the listbox is empty (no rows displayed) or not.

I have written ...

If MyList.ListCount = 0 then do something, else do something else

This is refusing to work properly under some circumstances, as follows ...

(I've put in a message box to tell me what the code thinks the list count is)

If this is a new record, the code thinks the ListCount is 1, even though the list is empty on the form (and should be, as it has no row source until the record is saved).

If the user is editing an existing record, and the list box is displayed as empty, the code knows it is empty and tells me the ListCount is 0.

This seems to me to be very bizarre! Can anyone explain?

(By the way, what has happened to the Help system in Access 2007? MS seem to have changed it for me without consultation and it's gone from being annoying but reasonably helpful to totally unhelpful overnight!!)
May 4 '10 #1
6 7076
Megalog
378 Expert 256MB
@julietbrown
Very strange.. I just confirmed this myself. When there is no row source for the object, it still reports the listcount as a 1.

I suggest using:

Expand|Select|Wrap|Line Numbers
  1. If Me.MyList.Rowsource = "" Then
  2. 'Do something
  3. End If
May 5 '10 #2
Sadly, I already tried your suggestion!! So, I know that's what it "thinks". I've tried all sorts of dubious things to encourage it to think differently, and it does as long as it's not a new record, even though the row source is just the same under those circs. Well, I'll let you know if/when I find a solution. It's very annoying as it's quite a critical issue for me.
May 5 '10 #3
Megalog
378 Expert 256MB
Hm.. can you explain why you're changing the rowsource to the listbox in the first place? You are checking to see if the control has a rowsource for that record, not if you have selections made, right? I just want to make sure the problem is being stated correctly here, since I've never had a case where i change the rowsource to a control like this on separate records.
May 5 '10 #4
I will try to explain! When a new 'Event' record is created and saved, the system generates a set of standard document titles associated with it (e.g., one is 'Invitation ...') and displays them in a listbox on the form. But, of course, when an Event is just edited, you don't want the system to create these again (to make two copies of all of them). So, my AfterUpdate routine looks to see if the set of docs is empty, and if it is it knows to create them, otherwise it knows they have already been created.

But it's ok ... I'm just going to base the decision on whether these docs are already in the underlying table, instead of checking whether the list box is empty. That will solve the current problem. It's frustrating not to understand why Access thinks an empty list box has an entry in it, though!

I have to leave this problem now, as I've found a far worse one that I've no idea how to deal with (see my new post if you have the time/patience/energy!)
May 6 '10 #5
NeoPa
32,556 Expert Mod 16PB
I have to leave this problem now, as I've found a far worse one that I've no idea how to deal with (see my new post if you have the time/patience/energy!)
NB. The thread referred to is probably How can I trap clicking of 'Cancel'/hitting CTRL + Z?.
May 6 '10 #6
I was asked to 'choose a best answer'! But in this case, there really isn't one. It remains mysterious. But the work around was to DCount the relevant records in the underlying table ... so I guess that's my own best answer!
May 15 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
1
by: Randy Harris | last post by:
I can easily select a row in a listbox with: Me.lstMyListBox = "Some Data" if "Some Data" is in a record in the bound column. Is there any way to select a record based on a column other than the...
7
by: Colleyville Alan | last post by:
I have an app in which users are displayed a list of mutual fund from which they can choose. There is a listbox embedded in a two-tabbed notebook control. When the form is initally opened, the...
4
by: Alienz | last post by:
I have a subform where I have a subform with 20 options to select from. When I set the multiselect property to simple and select multiple options, nothing is stored. I have another table with...
4
by: deko | last post by:
I have an Access 2003 mdb with a Main Form that has a ListBox with a long list of items. The problem is the scroll bar on the ListBox does not scroll all the way to the end unless you first scroll...
13
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
3
by: BVH | last post by:
Hi, I'm currently having a problem with a vb6 project I once wrote that needs to be converted to vb.NET. The problem is as follows : On a form I have a listbox and two commandbuttons. The 2...
1
by: andrew.panin | last post by:
Hi there! I've got a trouble with these things. What's going on? 1ST STEP: we have ListBox item. Let's call it ListBox1. We're adding four values to it using AddItem method:...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
1
by: dkohel | last post by:
I have 2 list boxes on my form. I am trying to populate listbox B with the selection from listbox A. I have set multi-select in both boxes to Extended... The user will select the items from...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.