Multiple Selects

G

Guest

Hi All,

This is probably a easy question to answer and I have tried a few things but
with no luck. I am using a connection to a database to get some data out of
it and display it in Excel, the code looks some thing like :-

Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=XXX;UID=XXX;pword=XXXAPP=Microsoft®
Query;WSID=XXX;DATABASE=XXXX;Network=DBMSSOCN;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.CommandText = Array("select * from TABLE")
Debug.Print .CommandText
.Name = "Sheet1"

This code just places the return results in Sheet1 starting from Cell's A1,
what I would like to do is in the same module call a second select statement
and place the results in the same sheet but starting from D1, I have tried a
few things but I can only get the first select's worth of data to show and
nothing else.

If anyone could help that would be great.

Thanks

Phil
 
A

Andibevan

Hi Phil,

I may be missing something but would you merely need to change
Destination:=Range("A1")) to Destination:=Range("D1"))?

Andi

Hi All,

This is probably a easy question to answer and I have tried a few things but
with no luck. I am using a connection to a database to get some data out of
it and display it in Excel, the code looks some thing like :-

Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=XXX;UID=XXX;pword=XXXAPP=Microsoft®
Query;WSID=XXX;DATABASE=XXXX;Network=DBMSSOCN;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.CommandText = Array("select * from TABLE")
Debug.Print .CommandText
.Name = "Sheet1"

This code just places the return results in Sheet1 starting from Cell's A1,
what I would like to do is in the same module call a second select statement
and place the results in the same sheet but starting from D1, I have tried a
few things but I can only get the first select's worth of data to show and
nothing else.

If anyone could help that would be great.

Thanks

Phil
 
G

Guest

Hi Andi

Thanks for the reply, what I mean is I want to run both of the select
statments from the same macro, so that I have the data from select (1) in
column A1 and the data from the select (2) in D1, sorry I should of explained
better, my fault.

Thanks again, Philip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VB, Pivot Table, Refresh 1
Connection from Excel to SQL 6
Macro's 9
SQL ODBC Connection 1
Database Connection 1
Database query. 6
Call SQL Server Stored Procedures with parameters, 3
SQL Syntax Error in Query 2

Top