ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA and SQL (https://www.excelbanter.com/excel-programming/342831-vba-sql.html)

Brian

VBA and SQL
 
I have a worksheet that I want to query using SQL. I do not want to
filter the data. This is what I have done so far and I get an error.
I have a class modlue "rpt" with dataws defined as a specific sheet in
my workbook, wb is the activeworkbook, rptDatabase is the named range
I want to query. my conncection string is set up as follows. Do I
need to add a reference to make this work and if so which one? I
appreciate any help you might have.

Public Property Get ConnString() As String
ConnString = "Driver={Microsoft Excel Driver (*.xls)};" _
& "DriverId=790;" _
& "Dbq= " & wb.Path & "\" & wb.Name & ";" _
& "DefaultDir=" & wb.Path & "\" & wb.Name
End Property



Dim mySQL As String
Dim qt As QueryTable
mySQL = "Select Market, Specialty FROM [rptDatabase] WHERE
Market='Ped'"
Set qt = rpt.dataws.QueryTables.Add(rpt.ConnString,
rpt.dataws.Cells(1, 43), mySQL)
qt.Refresh



All times are GMT +1. The time now is 12:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com