close
Yes it's definitely possible if you handle your queries with VBA. Don't know
if Excel's Data menu option to query an external database can. Actually, I
think it can't

Check out these KB articles

support.microsoft.com/kb/295646

support.microsoft.com/?scid=h...412/en-us/quot;Preacher Manquot; wrote:

gt; I have a situation that I hope someone can give me a good answer to. Please
gt; bear with me as I try to explain my needs.
gt;
gt; My goal is to have an Excel spreadsheet that pulls from a SQL database and
gt; the the query pulls from a variable in the Excel sheet. For example let's
gt; say I am pulling Sales Orders from SQL, let's also simply assume the record
gt; has two fields Year and SOno.
gt;
gt; Under a simple query I could say Select * from table. Of course that would
gt; pull all so's from every year.
gt;
gt; To filter the query of course I could say Select * from table where
gt; year='2006'. And naturally that would give me 2006 orders.
gt;
gt; OK, here's where I can't figure this out. I want the query to filter
gt; according to a value in a cell in excel. Let's use cell A1. Essentially I
gt; am looking for a query that says quot;Select * from table where Year=(Cell A1 in
gt; the Sheet)quot;
gt;
gt; Is this possible?
gt;
gt;
gt;

Thanks for the tip on the parameters. I didn't know it was there. But I
still have a problem.

The select statement I am using is just a little complex, but it is too
complex for MS Query to display graphically. So when I use the where
field=? and run the query, it comes back and says quot;Parameters are not
allowed in queries that can't be displayed graphicallyquot; Please tell me
there is a workaround.

Thanks.

quot;Duke Careyquot; gt; wrote in message
...
gt; Yes it's definitely possible if you handle your queries with VBA. Don't
gt; know
gt; if Excel's Data menu option to query an external database can. Actually,
gt; I
gt; think it can't
gt;
gt; Check out these KB articles
gt;
gt; support.microsoft.com/kb/295646
gt;
gt; support.microsoft.com/?scid=h...412/en-us/
gt;
gt;
gt; quot;Preacher Manquot; wrote:
gt;
gt;gt; I have a situation that I hope someone can give me a good answer to.
gt;gt; Please
gt;gt; bear with me as I try to explain my needs.
gt;gt;
gt;gt; My goal is to have an Excel spreadsheet that pulls from a SQL database
gt;gt; and
gt;gt; the the query pulls from a variable in the Excel sheet. For example
gt;gt; let's
gt;gt; say I am pulling Sales Orders from SQL, let's also simply assume the
gt;gt; record
gt;gt; has two fields Year and SOno.
gt;gt;
gt;gt; Under a simple query I could say Select * from table. Of course that
gt;gt; would
gt;gt; pull all so's from every year.
gt;gt;
gt;gt; To filter the query of course I could say Select * from table where
gt;gt; year='2006'. And naturally that would give me 2006 orders.
gt;gt;
gt;gt; OK, here's where I can't figure this out. I want the query to filter
gt;gt; according to a value in a cell in excel. Let's use cell A1. Essentially
gt;gt; I
gt;gt; am looking for a query that says quot;Select * from table where Year=(Cell A1
gt;gt; in
gt;gt; the Sheet)quot;
gt;gt;
gt;gt; Is this possible?
gt;gt;
gt;gt;
gt;gt;
Use vangelder.orcon.net.nz/ QueryEditor to get around this
limitation.
BTW a table cannot be a variabl/parametere in an SQL query so you'll
need to update the SQL statement manually for each TABLE.
Using VBA would be the best. Here is some speudo code you could use
after you created the Query manually first

DIm qtb as QueryTable
DIm strTable as String
Const Query = quot;Select * FROM %TABLE% where year=?quot;

Set qtb = Activesheet.QueryTables(1)
qtb.CommandText = Query
strTable = Inputbox(quot;Enter a table Namequot;)
qtb.CommandText = replace(Query,quot;%TABLE%quot;,strTable)
qtb.refresh

DM Unseen
arrow
arrow
    全站熱搜

    software 發表在 痞客邦 留言(0) 人氣()