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!!)
6 7076 @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: - If Me.MyList.Rowsource = "" Then
-
'Do something
-
End If
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.
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.
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!)
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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,...
| |