Solved

Populate Excel 2007 ListBox with TSQL Query Result Set

Posted on 2013-01-14
2
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Technology Partners: 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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

630 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