Solved

Populate Excel 2007 ListBox with TSQL Query Result Set

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

735 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