Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing SQL DB into Excel sheet code

Status
Not open for further replies.

Hueby

MIS
Oct 20, 2004
321
US

Hi all, I'm am wanting to pull some data from a table in a Microsoft SQL server db, and import it into a excel sheet. I currently am using this code:

Code:
Sub Pull_JobNumbers() Dim qt As QueryTable sqlstring1 = "select JOBNUMBER from TABLENAME" connstring = "Driver={SQL Server};Server=SERVER;Database=test1;Uid=sa;Pwd=blah" With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A2"), Sql:=sqlstring1) .Refresh End With End Sub

When I run this macro, I just get a error that says "400". I'm wondering if there is a problem with my connection string, or the code in general?? Everything else seems okay to me, where do I begin troubleshooting this? Thank you for any help!
 
Stab in the dark:
[tt]
...
sqlstring1 = "select JOBNUMBER from TABLENAME;"
...[/tt]

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top