Solved

Populate Excel 2007 ListBox with TSQL Query Result Set

Posted on 2013-01-14
2
443 Views
Last Modified: 2013-01-14
I have an Excel worksheet named "Single-Column" that has a Form Control List box which I want to populate with the result set (single column) from a TSQL Query against a SQL Server 2008 R2 database table column using ADO.  I've placed the attached code in a module, but am getting a compile error when I try to reference Sheet1.Name, which is valid syntax.

Attached is the code that I am working with.  What am I doing wrong?

Thanks,

WW
PopLstBxFrmSQLSvr.txt
0
Comment
Question by:usernameX
2 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 38776650
You can't use a With statement to execute code.

If you want to rename the worksheet try this.
With Sheet1
    .Name = "Single-Column"
    With .ListBox158
        .Clear
        .BoundColumn = k
        .List = Application.Transpose(vaData)
        .ListIndex = -1
    End With
End With

Open in new window

That should fix that problem, but I think you might have a problem on the next line.

It won't work if the listbox is a Forms listbox, it would work for an ActiveX listbox though.
0
 

Author Closing Comment

by:usernameX
ID: 38776758
Duh!,

Thanks.

WW
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now