Results 1 to 9 of 9

Thread: [resolved] unbound listbox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Resolved [resolved] unbound listbox

    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.
    Last edited by rickford66; Aug 18th, 2005 at 12:23 PM.

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: unbound listbox

    Set the Row Source Type of the Value List to allow the entries to be added..

    To clear the list do..

    VB Code:
    1. lstBox1.RowSource=""

    To Additems do the following

    VB Code:
    1. lstBox1.AddItem "Data Item"
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: unbound listbox

    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.

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: unbound listbox

    Quote Originally Posted by rickford66
    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:

    VB Code:
    1. Private Sub Command2_Click()
    2.     Me.List0.RowSource = vbNullString
    3. End Sub
    4.  
    5. Private Sub Form_Load()
    6. Dim a As Long
    7.  
    8.     With Me.List0
    9.         For a = 1 To 20
    10.             .AddItem "This is " & a
    11.         Next a
    12.     End With
    13. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: unbound listbox

    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...
    VB Code:
    1. Listbox.RowSource = vbNull
    To populate list...
    VB Code:
    1. Listbox.RowSorce = item1;item2;item3  'and so on
    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?

  6. #6
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: unbound listbox

    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.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: unbound listbox

    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.

  8. #8
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: unbound listbox

    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:
    1. TextVar = lstBox1.Column(0)
    2.   PosVar = lstBox1.Column(1)

    For an example of creating the sequence number please have a read through this thread..

    Simple Access
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: unbound listbox

    I believe that will work just fine.
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width