Hello,
I am trying to use a list box in Access 2000 in which the list box is unbound. I want to, in VBA, to be able to clear the list and populate it with lines of text as I see fit. Does anyone know how to do this?
Thanks.
Printable View
Hello,
I am trying to use a list box in Access 2000 in which the list box is unbound. I want to, in VBA, to be able to clear the list and populate it with lines of text as I see fit. Does anyone know how to do this?
Thanks.
Set the Row Source Type of the Value List to allow the entries to be added..
To clear the list do..
VB Code:
lstBox1.RowSource=""
To Additems do the following
VB Code:
lstBox1.AddItem "Data Item"
Having trouble with lstBox1.AddItem "Data Item" line. Access 2000 doesn't seem to be understanding .AddItem. Is it possible the syntax is different?
Thanks.
This worked for me:Quote:
Originally Posted by rickford66
VB Code:
Private Sub Command2_Click() Me.List0.RowSource = vbNullString End Sub Private Sub Form_Load() Dim a As Long With Me.List0 For a = 1 To 20 .AddItem "This is " & a Next a End With End Sub
No, that doesn't work for me either. I'm using Access 2000. I did find something on another site that is working, but it is sloppy in my opinion.
To clear list...
To populate list...VB Code:
Listbox.RowSource = vbNull
I haven't tried to access the list to determine which item is selected yet. I hope to work on that today. With this approach, I have to create a string using a loop that would otherwise add items. I have to add the items to the string while ; delimiting the items. Then, I have to set .RowSource equal to the string. Sounds harder than it should be. Thoughts?VB Code:
Listbox.RowSorce = item1;item2;item3 'and so on
Access 2000 doesn't support .AddItem, it's a Xp and above supported feature.. should of remembered that.. you are going to have to manipulate the rowsource with a string..
However it will depend on how many items you are trying to place into the listbox? and also how the information is being entered? If you can let me know these two things then I'll be able to advise further.
There can be up to 100 items on the list. I would have liked to have added each item with the .additem. I'm not sure if I can make a string large enough for this. My Access experience is extremely limited. In trials with 4-5 lines, so far it has worked, but now I'm trying to figure out how to know which line is selected when I double click on the line. I have a double click event sub created, but having trouble getting it to report the right number of the line I double clicked. As for how the info is entered, I'm running through a table, doing multiple searches and keeping track of which items in the table match all of the search criteria. Then, I go back and populate the list box with those entries.
If there are going to be a large number of items needed on the list then you would be better placing these into a table and then set the rowsourcetype to Table/Query and then pull the information out of the table via an SQL entry in the RowSource.
To determine the number of the line use the listindex property of the list box to return the line item number, or if that is not going to be of use then consider creating a sequence number inside the sql for the recordsource and set the number of columns to be 2 with the column width being the width of the control followed by ;0cm This effectively hides the second colum from view. On the double click of the list box you can pick up the text and position like the following..
VB Code:
TextVar = lstBox1.Column(0) PosVar = lstBox1.Column(1)
For an example of creating the sequence number please have a read through this thread..
Simple Access
I believe that will work just fine.
Thanks.