PDA

View Full Version : write SQL table output to excel using VBA



BMD4
07-07-2018, 04:03 PM
Hi,

I've created ODBC connection.Now, I need to connect to tables and write data to excel in 3 different sheets (Tab1,Tab2,Tab3).

I have written code to connect to DSN and a sub procedure which has select statements for 3 tables.(select * from tab1..tab2..tab3)

Can any one suggest the code on how to get the output of these queries to excel in 3 tabs

Thanks in advance

snb
07-08-2018, 01:14 AM
.copytorecordset

stanl
07-09-2018, 02:56 AM
Assuming the data is returned as either an ADO or DAO Recordset this should help

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-copyfromrecordset-method-excel

Aflatoon
07-09-2018, 05:59 AM
Or just use a query instead of code.