Fill a combobox from code

  • Thread starter Thread starter Al Newbie
  • Start date Start date
A

Al Newbie

I have an access frontend and SQL Server backend. I don't want to link any
tables but prefer to use ado.

I have a combobox that I want to populate with the result of a recordset.

Here is the code I am using:
Do While Not rsSQL.EOF
cbxCustFrom.AddItem rsSQL!Customer, 0
rsSQL.MoveNext
Loop

This works fine except that I would like to add a 2nd field

I have tried adding
cbxCustFrom.AddItem rsSQL!Name, 1

before the rsSQL.MoveNext but get the error Can't add item. Index too long

What am I doing wrong?

Thanks
 
Hi,

You loose almost any benefit that can supply Access Forms by not using
linked tables. To the contrary with VB6, Access Forms performance is better
when you use linked table than when you define your own recordsets.

In this case, you could use RowSource, with an SQL statement supplying
the two fields, rather than a recordset and then, a loop with AddItem. You
also change the ColumnCount to 2 and may specify non default for
ColumnWidths, a delimited list of widths.


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top