VBA and SQL

B

Brian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top