manage items in a list box

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:09
Joined
Sep 12, 2006
Messages
16,051
I have a list box on an unbound main form, which contains a rowsource consisting of files in a certain folder. The listbox is unbound

when I change an item in a subform, the listbox should update to show different items from the same folder.

Now it is updating correctly, so the rowsource appears to be correct, , but then the listbox behaves strangely - with the first item being sort of permanently selected - or at any rate - strange selection behaviour

Anyone seen this sort of behaviour?



-----

out of interest, changed it to a combo box and it works correctly. so there must be some difference between the two?


----

After investigation, it might be this

http://stackoverflow.com/questions/3843784/listbox-is-selecting-many-items-even-in-selectionmode-single

the appearance is similar to what is described in the thread.

although I have played with the strings to get them shorter without getting it work correctly. very strange

----
further

if I run the code to update the listbox from the subform, either directly, or by running as sub IN the main form, it produces this strange behaviour. If I run exactly the same code directly IN the main form, it seems to work properly.
 
Last edited:
is the listbox set to multiselect? It may be you need to set the selected property to no.
 
no - the code is right.

- after playing around, and a lot of testing, it appears to be an issue caused only by updating the list box either by using code directly the subform, or by calling a proc in the mainform.

I have got round it, by not trying to use the subform at all, but just clicking a "repopulate" button on the main form, which uses exactly the same bit of code.
 
As I understand it, running code in the subform, or running a procedure on the main form with code from the subform causes the problem.

Running code from a command button on the main form does not cause the problem.

Have you tried a refresh or repaint?
 
tried everything, requery, doevents, etc etc

the combo box populates, but then behaves strangely. The appearance is like the link I mentioned, but the values are definitely all different. I can only think the interaction between the subform and the mainform does something to prevent the list box functioning exactly correctly.

The strange thing is - once the subform "screws up" the list box behaviour, the mainform then doesn't help it work properly.
 
Last edited:
Unbound combos definitely have bugs.

FWIW Try reading the Text property of an unbound combo on a form with a filter that returns no records.
 
I recently upgraded someone else's MS Access database (Never Again) to an SQL Server back end with a runtime front end on a Citrix environment. Everything worked fine in my local MS Access copy; however I had numerous strange breakages within the MS Access runtime environment. I discovered that everything in the runtime environment had to be explicitly declared and addressed. I'm wondering if something similar is happening here and you need to specifically address the form.
 
nice thought, Uncle Giz - but no joy

I am going to try and put together a demo I can upload.
It might just be this dbs/form - so it is worth doing.
 
Right

I just created a demo, and it worked correctly - so I must have a corruption in my form.

So I will create a new form, and try again.
 
fixed it in a different way

I never got to the bottom of it. Instead, I decided to push the files into a temp table, and base the listbox on the table - and it works fine now.
 
My preferred technique for listboxes is the fabricated ADO recordset. They can easily be loaded directly using a loop though anything. Ideal for listing things like filenames, tablenames etc.

Not having a table base they avoid the need for requerying anything by the engine.

Plus you get the Filter and Sort methods which are are far simpler to use than reorganising a list rowsource.
 
Galaxiom.

yes, the idea of using the rowsource string was to keep it all in memory, rather than have to use a table. I am not familiar with ADO, though - do you have a link

I don't need to sort it as - the file names incorporate the date, I just needed to collect the data.
 
If you just needed to collect the data, rather than display it, you could have used an Array.
 
I want to use it. The list box shows the files associated with a givenselection, so that they can be selected and used.
 
Are you sure a file selection dialog window would not be a prettier solution?
 
no - it's all working now

effectively, this is what I am doing

I have a folder that is going to save pdfs of documents

when I navigate to a different customer, I want to pick up all the documents previously sent to this customer, so I am doing this by a matching file search on the folder. Then the user can just select any of these to open without having to do any browsing. I want the list to be available without the user having to open a file browser.

my initial idea was to build these into a row source for a list box - but because of the problem I had, I am now storing the details in a temporary table, which is working fine.

Interestingly, putting the file list into a row source for a combo box didn't produce any problems - but for this I wanted a list box.

And the demo I tried to put together also worked correctly. I actually rebuilt both forms completely to see if there was a minor corruption, but it still didn't work - so something is going on.


-------------
here is a working demo of what I was doing

just create a subfolder in the project path, create a few dummy files, and enter details in table1 to filter some of the files, then open form1

ignore the bit in the middle. that was a deliberate attempt to stop it working

View attachment listboxdemo.zip
 

Users who are viewing this thread

Back
Top Bottom