Results 1 to 7 of 7

Thread: [RESOLVED] MS Access VBA addItem List view

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] MS Access VBA addItem List view

    I am getting an error on this line of code, hope someone can help.
    As you can see all I want to do is loop through the dataset and add column 1 to a list view for each row.
    VB Code:
    1. Me.lstEmpStates.RowSourceType = ValueList
    2. While Not rs.BOF And Not rs.EOF
    3. [U]Me.lstEmpStates.Additem rs.DataMember(rs.RecordCount, 1)[/U]
    4. rs.MoveNext

  2. #2

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: MS Access VBA addItem List view

    Me.lstEmpStates.Additem
    This is the offending piece of code I think. Error Method or data member not found. I have set the source type to value list so cant see the problem?
    Anyone?

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: MS Access VBA addItem List view

    I think to use the .AddItem on a listbox it has to be a CommandBar listbox, which I've never used. The listbox control in the toolbox doesn't have an .Additem method that I know of. You can set the contents to a data source, like a table or query, or enter a value list.
    Tengo mas preguntas que contestas

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: MS Access VBA addItem List view

    OK yes add item is on 2003 and im on 2000.
    I have a workaround by using a value list
    i.e Build a comma delimited string then
    Me.lstEmpStates.RowSource = strStates

    My trouble now is building the string

    While Not rs.BOF And Not rs.EOF

    strStates = strStates & ";" & rs.DataMember(0, 1)
    rs.MoveNext

    Wend

    As you can see I am just wanting to get column 1 into the string as I loop through the record set but the syntax is wrong.

    hlp pls

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: MS Access VBA addItem List view

    what is rs?
    what is datamember?

    if rs is a recordset then use rs("<fieldname>") - will work except (possibly) for null values.

    Also there is a character limit on the list box for values, but if you are not going near that limit you should be ok.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: MS Access VBA addItem List view

    Thanks Ecniv
    http://msdn.microsoft.com/library/de...html/ino2k.asp
    Also keep in mind that there's a limit on just how long a control's RowSource property can be, and that limit is 2,048 characters
    I think that should be enough

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: [RESOLVED] MS Access VBA addItem List view

    Another option is to write the values you want to a temp table and use that as a rowsource. That way you could sort, select, etc.
    Tengo mas preguntas que contestas

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