Runtime error 2176

Posted on 2005-04-29
Last Modified: 2011-09-20
I'm trying to pull a list of values into a listbox and the concantenated length is greater than the listbox allows (something like 2000 characters I think).  I've read stuff that says to put it in a table but the underlying data changes daily so I suppose it has to be created dynamically.  Could somebody help me out with the syntax please?  Thanks! -j

strSQL = "SELECT DISTINCT a.CurrentPayorDesc "
strSQL = strSQL & "FROM RepGrp a ORDER BY a.CurrentPayorDesc;"
  Set rst = dB.OpenRecordset(strSQL)
  'PayorDD.RowSource = "All Payors"
  payorlist = "All Payors"

  i = 1
  Do Until rst.EOF
   tmp = rst.Fields(0)
   payorlist = payorlist & ";" & tmp
   'PayorDD.AddItem tmp, i
   i = i + 1
 PayorDD.RowSource = payorlist
Question by:artgal
    LVL 4

    Expert Comment

    You should just put the SQL statement in the Row Source property of the listbox.

    Right-click on the listbox in design view and select Properties to open up the Properties window.
    Select the Data tab, select the Row Source Type property to be Table/Query, and put the following in the Row Source property:

    SELECT DISTINCT CurrentPayorDesc FROM RepGrp ORDER BY CurrentPayorDesc

    This should fill the listbox with items from the CurrentPayorDesc field in the table RegGrp.

    If you need to do this in code:

    PayorDD.RowSource = "SELECT DISTINCT CurrentPayorDesc FROM RepGrp ORDER BY CurrentPayorDesc"
    LVL 4

    Accepted Solution


    If the listbox is not bound to a Control Source, you will need to make a call to the method ayorDD.Requery after setting the RowSource.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now