I have this code:
I get error when I run this code:Code:Dim WithEvents dbConn As ADODB.Connection Dim sql as string sql = "SELECT * INTO [Worksheet1] IN ''[Excel 8.0;Database=" & CurrentProject.Path & "\MyExcel.xls] FROM MyTable" Set dbConn = New ADODB.Connection dbConn.Open "Provider=SQLOLEDB;Data Source=myComputerName\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI;" dbConn.Execute sql
I am guessing the ADODB cannot run a query like that.Code:ADODB conn error: -2147217908, Command text was not set for the command object., Microsoft OLE DB Provider for SQL Server, 1000440, C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA7.1\1033\VbLR6.chm
How can I export query result to xls file by using ADODB connection?
Is is possible? Or which is a proper way to do it?




Reply With Quote
