Adding elements to a list (1 Viewer)

C

Carlos Mendoza

Guest
Hello,

This may be pretty simple, but I haven't found anything in the documentation that helps me with it.

I want to add a list in a form which is going to be filled with the results from a query that I build during run time.

Is it possible to just add rows to the list from a Function or Sub?

Any help would be appreciated

Thanks
 
C

Carlos Mendoza

Guest
I hate when I answer my own posts, but here it is for someone that might find it useful

You have to ser the RowSourceType roperty to Values List, and then this code will do it:

'Set Database
Set dbs = CurrentDb


strSQLQuery = "SELECT C1,C2,C3 " _
& "FROM T1 " _
& "WHERE C1 = 'Something' " &
Set rst = dbs.OpenRecordset(strSQLQuery)
lst.ColumnCount = 3
lst.RowSource = ""

With rst
Do Until .EOF
lst.RowSource = lst.RowSource & rst!C1 & ";" & rst!C2 & ";" & rst!C3 & ";"
.MoveNext
Loop
.Close
End With
 

Users who are viewing this thread

Top Bottom