List box question

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â€
 
D

Douglas J. Steele

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)
 
F

fredg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top