none
Listbox display RRS feed

  • Question

  • I am trying to display a list of items an individual has been issued. The items are showing up in the immediate window but not in the list box. This is the code:

                rsc.FindFirst "[Stock_Number] = " & Chr(34) & rsi(0) & Chr(34)
                item = rsc(2)
                Me.lstItems = rsi(2) & item & rsi(3) & rsi(7)
                Debug.Print rsi(2) & item & rsi(3) & rsi(7)
                rsi.FindNext "[PRI] = " & Chr(34) & pin & Chr(34)


    Monday, September 30, 2019 7:27 PM

All replies

  • Is your listbox set to Value List?

    You need to use AddItem to add items to the list


    Daniel Pineault, 2010-2019 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Monday, September 30, 2019 7:43 PM
  • Normally a subform in continuous forms or datasheet view would be used for this, but if you really want to use a list box you might like to take a look at StudentCourses.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to  amend the form design accordingly.  

    If you have difficulty opening the link, copy the link (NB, not the link location) and paste it into your browser's address bar.

    This little demo file includes an example of how the courses for which a student is registered are represented in a multi-select list box.  A subform, as also illustrated in the demo, is code-free and simple to implement. More fundamentally a list box does not allow any non-key attributes of the relationship type.  Status is the example in my demo; in your case it might be DateIssued for instance.

    A value list should not be used as a list box's RowSource where the items represent data, as is the case here.  A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as values at column positions in rows in tables, and in no other way, so encoding data as part of the object definition is a violation of this rule.  From a practical point of view, where the values are in rows in a table, adding a new item is merely a matter of inserting a row into the referenced table, which in a subform is easily done by means of the NotInList event procedure.  With a list box my demo includes a button which opens a dialogue form to insert the new row.

    If you simply want to show the items issued per employee as a read-only line or comma separated list, rather than as selected items in an updatable list box, my demo also includes illustrations of how to do this, again with a button to edit the list by opening a dialogue form.

    Ken Sheridan, Stafford, England


    • Edited by Ken Sheridan Monday, September 30, 2019 9:19 PM Typo corrected.
    Monday, September 30, 2019 9:17 PM
  • Thank you that worked for the most part. It is now showing me the dates(rsi(2) and the first work in the Item name rsc(2) but nothing else. If I change the format to 4 columns, I get more info. But not how I want it.
    Monday, September 30, 2019 10:50 PM
  • Hi Abbottjohn,

    You need to give more details of your problem.

    "item" is a reserved word in Access especially for your ListBox.

    Just below "Option Database"......add a new line.....put "Option Explicit". This will help you solve unknown variables which might not be declared.

    Wednesday, October 2, 2019 2:01 AM