Solved

Populate Excel 2007 ListBox with TSQL Query Result Set

Posted on 2013-01-14
2
465 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

777 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