2
2
I have tried really hard to solve this issue but I think I am going to need a little help. I can program in different languages but I don't have any experience with Excel, VBA or the queries you can make so please feel free to treat me like a little kid and mention all the little details.
What I would like to do is to take the contents in three different cells, and use them as parameters in a SQL query.
Right now I have no problems creating the query as mentioned here Run an SQL Query With a Parameter from Excel 2007 and I can choose the parameters from the cells ONCE (by replacing the strings with '?').
But I would like to call the query multiple times as a normal function, just by putting it in a cell like '=MyQuery($A$1,$A$2,$A$3)'
The "Database" is just another Excel file chosen from External sources so I don't know if things change in the VBA code.
I would be really helpful if you can point me in the right direction, even if they are just pieces of the puzzle. I need a way to get to the query, a way to modify it and a way to execute... but as usual, the devil is in the details.
Actually, it would be perfect if the excel file (with the data) and the sql query could be controlled from the function too. Like that all I need to do happens in one place. Thanks! – Terco – 2011-06-08T23:45:41.413
Make sure and check out the limitations of UDFs here. It may not matter for what you're doing but they're not being specific enough about which methods can't be called.
– Lance Roberts – 2011-06-09T06:52:54.470I left a short answer to get you going. I'll try and find time tomorrow to flesh it out tomorrow when I can run some tests. – Lance Roberts – 2011-06-09T07:12:39.967
putting together a query string is one thing, but how elaborate will it need to be? Do you want to parameterize the table name, the fields and criteria? Would seem like 3 parameters might not cover much, and it will be difficult to create a function without more information – datatoo – 2011-06-09T11:57:20.973