Multi Column Listbox

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Multi Column Listbox

Post by Cecilia »

Hi All!

I've been away from programmabling for a bit. And now that I'm back, I'm stuck. I know how to do this in Access, but I have to do it in Word.

How do I fill a multicolumn listbox?

I'm using a DAO recordset (I know I should learn ADO, but it's confusing for me since I don't do it much anymore) as the source for the data, so...this is what doesn't work (and a bunch of variations on it):

Set rst = db.OpenRecordset("SELECT Agency, AgencyType FROM tblAgencyAddresses GROUP BY Agency, AgencyType;", dbOpenSnapshot)
rst.MoveLast
rst.MoveFirst
Do While Not rst.EOF
lstAgencyType.AddItem rst!Agency & "; " & rst!AgencyType
rst.MoveNext
Loop

What this results in is my listbox with a bunch of agency names followed by a ; (but AgencyType doesn't show up at all) which is not what I want. I want Agency in one column and AgencyType in another (I already have columncount set to 2). Ultimately I'll have a dropdown to choose agency and populate AgencyType, which will then populate AgencyLocation, from which the BoundColumn will be AddressID (so that the address will be populated in the document) but I can't get past this hurdle. :-/

TIA!

User avatar
mbarron
2StarLounger
Posts: 112
Joined: 25 Jan 2010, 20:19

Re: Multi Column Listbox

Post by mbarron »

Hi,
Using .AddItem only allows for the addition of information into the first column.

Try something like this:

Code: Select all

Dim alist()
ReDim alist(2, 0)
Dim i As Integer
Set rst = Db.OpenRecordset("SELECT Agency, AgencyType FROM tblAgencyAddresses GROUP BY Agency, AgencyType;", dbOpenSnapshot)
rst.MoveLast
rst.MoveFirst
Do While Not rst.EOF
    alist(0, i) = rst!Agency
    alist(1, i) = rst!AgencyType
    i = i + 1
    ReDim Preserve alist(2, i)
    rst.MoveNext
Loop
lstAgencyType.Column() = alist