PDA

View Full Version : ADO / Worksheet range display in userform



theta
08-13-2012, 06:12 AM
Hi, I been playing around with some ADO/ODBC (thanks for all the help) and am returning some nice recordsets.

I would like to be able to display the recordset in a userform as I later plan on allowing user to select the columns to import - and provide a field name in a text box.

What is the best way to do this? I can display the recordset directly from memory into the userform, or dump it onto a hidden sheet and display a range or view in the userform?

Any help appreciated :)

Kenneth Hobs
08-13-2012, 06:54 AM
Depends. If a few, use checkbox controls. If many, use a listbox control with multiselect property and liststyle=1 property for each item to have a checkbox.

Another option is to use a scratchsheet or filter the data and set the userform to modeless if they need to interact with it while the userform is shown.

Bob Phillips
08-13-2012, 06:58 AM
Just drop it into an array using GetRows, and access the records via the array.

theta
08-13-2012, 06:59 AM
filter the data and set the userform to modeless if they need to interact with it while the userform is shown.

Would you have an example of this - have not come across this method before.

Many thanks

theta
08-13-2012, 07:23 AM
Sorry XLD just saw your response as well. I have not used either of these methods, will have a google now ...

How would I display the array on the userform?

Bob Phillips
08-13-2012, 07:32 AM
It depends how you want to see them. If it is one record at a time, you would pull them from the array based on the index number. If you want to see a list, load the listbox with the array. You can pull a single column form the array using Application.Index, like so

Application.Index(ary, 0, 1)

Following on from Kenneth's filter comment, you can filter the recordset directly.

theta
08-13-2012, 07:52 AM
I was hoping to produce something like this - where I can scroll a recordset. I will then build on this and insert checkboxes / textboxes to select which fields are imported...

http://www.mediafire.com/conv/6b0f75a065767f227ba7addcdf4803370405dc35f5eb06d4424728ab95f23c746g.jpg

Bob Phillips
08-13-2012, 08:09 AM
Build a set of textboxes for the columns names, add checkboxes under each, drop the array into a listbox, and then process as selected.