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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to Excel from SQL Server using VB

Status
Not open for further replies.

Ynnx

Programmer
Dec 13, 2001
4
MY
Is it possible to use visual basic to code the transfer of data from a specific column in a table in SQL Server 2000 to a specific cell in Excel?
 

Yes. Are you working from Excel VBA or VB?

In both case the strategy is:
-Use ADO to open a connection to the SQL server.
-Open a recordset with the data the you want (using Tranaction SQL).
-Put the values into you excel sheet.
- Close the recordset and connection and destroy the objects.



Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Ynnx,

Sunja is Correct however i would change the process to:-

In both case the strategy is:
- Use ADO to open a connection to the SQL server.
- Open a Disconnected recordset with the data that you
want (using Tranaction SQL).
- Close and Release the Connection
- Put the values into you excel sheet.
- Close the recordset and destroy the objects.

Codefish
 
Thanks for your help.

Btw, I am working from VB6. When writing to Excel, would I be able to write cell by cell instead of column by column?
I supposed the code below writes column by column.

For i = 0 To 14
oRS.Fields(i).Value = oOrdersRS.Fields(i).Value
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top