I am trying to select data in an SQL Table that matches a list (or Table of part numbers I have in Excel 2007. The connection to the SQL database works but gives me the database field heading with no result. I can get a good result if I just use the SELECT query to be equal to a variable set to the value of a single cell.
Sub PNinfo()
It may be better to set this up as a Join between the SQL table and the Excel list (Range or List) but I think the main issue is, what is the syntax to get the passed through SQL statement to use the data in Excel.
Thanks for any suggestions
Sub PNinfo()
Dim sqlstring As String
Dim connstring As String
Dim PNList As TableStyle
Dim jbqt As QueryTable
Dim jbqt As QueryTable
sqlstring = "SELECT dbo.Quote.Part_Number, dbo.Quote.RFQ, dbo.Quote.Quote FROM dbo.Quote Where dbo.Quote.Part_Number = '" & ActiveSheet.ListObjects("PNList") & " '"
connstring = "ODBC;DSN=database32;UID=User1;PWD=password;DATABASE=PRODUCTION"
Set jbqt = ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Cells(7, 4), Sql:=sqlstring)
jbqt.Refresh
End Sub
It may be better to set this up as a Join between the SQL table and the Excel list (Range or List) but I think the main issue is, what is the syntax to get the passed through SQL statement to use the data in Excel.
Thanks for any suggestions