adding additional recordset to listbox

excel 2010 vba

I have listbox i'm populating from a recordset.

I would like to also add additional items to the listbox via another recordset.

Is this possible ?

do i just need to use the same code as below to add items from the other recordset and it will add without deleting the items i have already in the litsbox ?

         Arr = rst.GetRows
i = 0

With frmResultAll.ListBox1
        .ColumnHeads = False
        .ColumnCount = rst.Fields.Count
        .Column = Arr
        .ListIndex = -1
End With

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
Unless someone comes up with a better solution you can use a loop to add individual items of the second list using the command

frmResultAll.ListBox1.add individualitem
[ fanpages ]IT Services ConsultantCommented:

If both recordsets are generated from SQL statements, & each has the same number of columns (fields), then you will be able to join the two statements (& hence, the two sets of results) with a UNION statement.

If both SQL statements do not have the same number of columns, then this can still be achieved, by adding "filler" columns to one of the statements so that the quantity of columns is identical in each individual statement.

For example,

If the first recordset is generated from the following statement:

SELECT [Name] FROM [Address_List]

and the second statement is:

SELECT [Surname], [FirstName] FROM [Contacts]

The two could be joined as follows:

SELECT [Name] FROM [Address_List]
SELECT [FirstName] & " " & [Surname] AS [Name] FROM [Contacts]

The resultset would then be a Union of both statements (both collections of [Name]).

You could order the resultset in ascending alphabetical order, if you wished, as follows:

SELECT [Name] FROM [Address_List]
SELECT [FirstName] & " " & [Surname] AS [Name] FROM [Contacts]
[Name] ASC

I won't go on now, but if you have two SQL statements we can look at combining them as described.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
[ fanpages ]IT Services ConsultantCommented:
'Bump'! :)
FordraidersAuthor Commented:
[ fanpages ]IT Services ConsultantCommented:
You're welcome.

I presume the suggestion resolved your issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.