Query Table link input to cells

mjacobsen

New Member
Joined
Apr 26, 2006
Messages
11
Hello,

I have the following code to an external data source and I want to have a macro where I click the button and it links the 2 red data points to cells or an input box. So as to avoid the need for running the External query interface. If I put in a cell ref then I get an error box saying that C1 (for example) is not a valid column name.

Any suggestions?

With Selection.QueryTable
.Connection = _
"ODBC;DRIVER=SQL Server;SERVER=172.16.8.12;UID=gammabilling;PWD=gammabilling;APP=Microsoft Office XP;WSID=MJACOBSEN-DT"
.CommandText = Array( _
"SELECT vPriceInfo.Client_id, vPriceInfo.DESCRIPTION, vPriceInfo.clientservice_id, vPriceInfo.countrycode, vPriceInfo.citycode, vPriceInfo.Location, vPriceInfo.FirstUnitCharge, vPriceInfo.FirstRecurrin" _
, _
"gCharge, vPriceInfo.Startdate, vPriceInfo.Enddate, vPriceInfo.RATE" & Chr(13) & "" & Chr(10) & "FROM Financial.dbo.vPriceInfo vPriceInfo" & Chr(13) & "" & Chr(10) & "WHERE (vPriceInfo.Client_id=337) AND (vPriceInfo.clientservice_id=1) AND (vPriceInfo.Endda" _
, "te Is Null)" & Chr(13) & "" & Chr(10) & "ORDER BY vPriceInfo.countrycode, vPriceInfo.citycode")
.Refresh BackgroundQuery:=True
End With
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe try eg:

& "WHERE (vPriceInfo.Client_id=" & Range("C1").Value & ") AND (vPriceInfo.clientservice_id=" & Range("C2").Value & ") AND
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top