Use string variable as RowSource for listbox

M

Mr. Smith

Hi.

I try this as row source for a listbox

Dim sql as string

sql = "SELECT * FROM tblClients"

With myListbox
.RowSourceType = "Query/Table"
.RowSource = sql
End with

It does not work. Why?

This work:
With myListbox
.RowSourceType = "Query/Table"
.RowSource = "SELECT * FROM tblClients"
End with

Any contraints regarind variables as source for listboxes?

Mr. Smith
 
N

Nikos Yannacopoulos

Most likely because sql is a reserved keyword! Try using another
parameter name instead; strSQL is quite commonly used.

HTH,
Nikos
 

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

Similar Threads

ListBox RowSourceType and RowSource 5
Cascading ComboBox 1
Empty listbox 1
ListBox Rowsource 2
Requery a record in a form 2
Listbox Rowsource 11
depending listboxes 7
Apply value of a combo box as a filter 3

Top