PDA

View Full Version : Listbox Header



slamet Harto
03-31-2009, 04:41 AM
Hi there,

I have an userform with a listbox. I want to show a header for that listbox.
This listbox is populate some record from Acces (mdb).

is it possible to create listbox header from access fieldname thru vba?

any replies would be appreciate it.
Thanks & rgds, Harto

Bob Phillips
03-31-2009, 04:46 AM
No, you only get headers when you bind to a worksheet range.

p45cal
03-31-2009, 08:26 AM
..so if you queried the Access database from an excel sheet (hidden?), then make the Rowsource the querytable result (it'll be a named range called something like 'Query_from_Access_Database') not forgetting to set ColumnHeads to True. Then you could refresh the query just before showing the userform.

slamet Harto
03-31-2009, 07:10 PM
Hi P45cal

Can you send a sample workbook, please?

Thanks in advance.

p45cal
04-01-2009, 02:51 PM
See attached.
It queries the Northwind Database. The sql is querying the 'Orders Qry' therein, which I think is in itself a query within that database.
The path to my Northwind database was:
C:\Documents and Settings\myTest\My Documents\Northwind.mdb
so refreshing won't work without a database there in your system.
[you can choose the Browse option, when it complains it can't find the database, to find another database and you can thus create another query altogether]
The button on the sheet is self-explanatory.
I found I had to offset the querytable's named range down a row (and resize it to 1 fewer rows), which I did by creating another name, which I used as the rowsource for the list box.
Headers in the list box are there, generated solely by the headers in Access.