Use string variable as RowSource for listbox

  • Thread starter Thread starter Mr. Smith
  • Start date Start date
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
 
Most likely because sql is a reserved keyword! Try using another
parameter name instead; strSQL is quite commonly used.

HTH,
Nikos
 
Back
Top