Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Using VB, Excel and SQL Server together


Message #1 by andy@e... on Wed, 15 Aug 2001 11:09:19
Vincent,
Thanks for your continued interest.  I did actually ask a similiar 
question on google a few weeks back, but didn't get a conclusive answer.  
I then let it lie until I saw Toby's answer a few days ago - you know what 
it's like when you've got to much work and not enough time (start the 
violins somebody....).

Cheers,
Andy

> Dear Andy, 
> 
> Thanks for the compliment. :)
> 
> Regarding your second question, I'm sorry, 
> I don't have much experience with SQL. :(
> But I think Toby has provided a good starting
> point for you. 
> 
> In the meantime, perhaps you may post your question
> to other forums, see if other developers can help
> you. If I come across any articles that's similar
> to your question, I'll let you know.
> 
> Best regards,
> Vincent.
> 
> 
> > ' I've not tried this with SQL Server, but this'l work with
> > ' Access 2000 --> Excel 2000: This assumes that the following 
> Files/Tables
> > ' already exist:
> > '
> > ' File               Table
> > ' ====================    ===========
> > ' d:\Export\Source.mdb    Categories
> > ' d:\Export\Target.xls    Categories (* SEE NOTE)
> > '
> > '
> > ' It furthermore assumes the existence of the following Column
> > ' Headers/Fields/Column Names in both tables:
> > '
> > ' CategoryName , Description
> > '
> > '
> > ' * NOTE: This is actually a --> Named Range <-- in the Categories
> > ' Sheet/Table, or any other table for that matter; I've called the
> > ' range "Categories". I use VB and the Microsoft Excel 9.0 Object
> > ' Library to create named ranges under VB 6.0 programatically. If you
> > ' Export a complete Access Table to an Excel Sheet, the Named Range
> > ' in the Excel file is created automatically. The problem only crops
> > ' up with Sheets/Tables which have been created directly under Excel.
> > '
> > 
> > 
> > Dim oCon As ADODB.Connection
> > Dim sCon As String
> > 
> > 
> > sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >         "Data Source=d:\export\source.mdb;" & _
> >         "Persist Security Info=False"
> > 
> > SQL = "INSERT INTO Categories " & _
> >        "IN  'd:\Export\Target.xls'  [Excel 8.0;] " & _
> >        "SELECT CategoryName, Description FROM Categories"
> > 
> > Set oCon = New ADODB.Connection
> > oCon.ConnectionString = sCon
> > oCon.Open
> > oCon.Execute SQL
> > oCon.Close
> > Set oCon = Nothing
> > 
> > I tested this using the NorthWind.MDB
> > 
> > Regards,
> > -Toby

  Return to Index