Results 1 to 6 of 6

Thread: Access VBA listbox question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    Access VBA listbox question

    Hi,
    Please help with adding items to a listbox using a form in Access. I dont want to use the access wizard feature of having the listbox automatically populated. Rather I want to enter a value and have that value populate into the listbox.

    I thought i could just go:
    Code:
    list1.additem ("red")
    but it doesnt recognise the additem referance.


    Thanks!
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    Lively Member
    Join Date
    Apr 2001
    Location
    The Netherlands
    Posts
    112
    Hi,

    .AddItem should do the job. Dunno whats wrong there

    - did you watch the declarations (private, public etc)?
    - did u save the file?

    remvs

  3. #3
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    .AddItem does not exist in Access 97 List/Combo boxes.

    Get your recordset then:

    Code:
    Do While Not rs.EOF
        
        strData = strData & rs!dtmDateTime & ";"
            
        rs.MoveNext
        
      Loop
      
      If Not IsNothing(strData) Then
      
        strData = Left(strData, Len(strData) - 1)
      
      End If
      
      ComboName.RowSource = strData
    Edit: Isnothing is just a function I wrote to check for Nulls and Empties.

  4. #4
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: Access VBA listbox question

    Originally posted by SmagO
    Hi,
    Please help with adding items to a listbox using a form in Access. I dont want to use the access wizard feature of having the listbox automatically populated. Rather I want to enter a value and have that value populate into the listbox.
    I would have considered useing a seperate table List_of_Choices and use it to populate Combos and listboxes. Thatway I could edit it at runtime.
    ?
    'What's this bit for anyway?
    For Jono

  5. #5
    Lively Member
    Join Date
    Jun 2003
    Posts
    114
    The AddItem method is not available until Access 2002 ... Access 2000 doesn't have it either ... Depending on the # of items you need to put the list you can create a temporary table and populate it and bind that to the listbox or you can make the listbox a "Value List" and concat the items together into a string separated by semicolons and assign that string to the RowSource property ...

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    ya, vba listboxes are not nice in that respect.

    myListData = myListData & ";" & NewItem
    myList.RowSource = myListData

    ..... It's slow too.

    But there is good news!! You can use VB6 listboxes in VBA. Just use "Microsoft Forms 2.0 Listbox" from the "More Controls" list. Then you will notice you've got your .AddItem.. and all those other nifty VB6 options

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