List box question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

Is there a way to populate a list box on a form from SQL in VB. I know I
can base a List Box on a static query, but it would be easier for me to be
able to do it in my VB code if possible.

SQL Example:

vSQL = “Select number, Name, Address from MyTableâ€

docmd.runsql “vSQLâ€
 
Me.MyListbox.RowSource = vSQL

It might also be necessary to include

Me.MyListbox.RowSourceType = "Table/Query"

(FWIW, you can't use RunSQL for Select queries: only for Action queries)
 
Hello all,

Is there a way to populate a list box on a form from SQL in VB. I know I
can base a List Box on a static query, but it would be easier for me to be
able to do it in my VB code if possible.

SQL Example:

vSQL = ´Select number, Name, Address from MyTable¡

docmd.runsql ´vSQL¡

First make sure the ListBox RowsourceType property is set to
"Table/Query".
Then you can use:

vSQL = ´Select number, Name, Address from MyTable¡
ListBoxName.Rowsource = vSQL

Note:
Name and Number are both reserved Access/VBA/Jet words and should not
be used as field names.
For additional reserved words, see the Microsoft KnowledgeBase article
for your version of Access:

109312 'Reserved Words in Microsoft Access' for Access 97
209187 'ACC2000: Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'
321266 'ACC2002: Microsoft Jet 4.0 Reserved Words'

For an even more complete list of reserved words, see:
http://www.allenbrowne.com/AppIssueBadWord.html
 
Back
Top