<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bacon Bits: &#187; MS Query</title>
	<atom:link href="http://datapigtechnologies.com/blog/index.php/tag/ms-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://datapigtechnologies.com/blog</link>
	<description>A DataPig Technologies Blog</description>
	<lastBuildDate>Wed, 08 Sep 2010 12:25:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Running a SQL Stored Procedure from Excel (No VBA)</title>
		<link>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/</link>
		<comments>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/#comments</comments>
		<pubDate>Tue, 04 May 2010 18:02:39 +0000</pubDate>
		<dc:creator>datapig</dc:creator>
				<category><![CDATA[Excel Tips and Tricks]]></category>
		<category><![CDATA[MS Query]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Power Tips]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/</guid>
		<description><![CDATA[We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs [...]]]></description>
			<content:encoded><![CDATA[<p>We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs feel better.</p>
<p> </p>
<p>So today, I'll show you how to easily make Excel run a Stored Procedure to get data.</p>
<p> <span id="more-1965"></span></p>
<p><strong>Step 1:</strong> Data tab &#8211; &gt; From Other Sources -&gt; From SQL Server</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL1.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 2:</strong> Enter Credentials. Your server name can be an IP address</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL2.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 3:</strong> Choose any old table or view. Pick a small one because we'll discard it later anyway.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL3.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 4:</strong> Excel will pop up the Import Data dialog box. Click Properties here (NOT THE OK BUTTON).</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL4.png" alt="" /></p>
<p> </p>
<p><strong>Step 5:</strong> Click on the Definition tab. There, change Command Type to SQL, and then enter your Stored Procedure name in the Command Text input.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL5.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 6:</strong> Excel complains about something….blah…blah…blah. Click Yes – (as in yes I know what I'm doing).</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL6.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 7:</strong> Excel will activate the Import Data dialog box again. This time click OK to fire the Stored Procedure and return the results.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL7.png" alt="" /></p>
<p> </p>
<p> </p>
<p><strong>Step 8: </strong>Marvel at your results</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL8.png" alt="" /></p>
<p> </p>
<p> </p>
<p><span style="font-size:12pt"><strong>Notes:<br />
</strong></span></p>
<ol>
<li>Excel will fire the Stored Procedure each time you "Refresh"</li>
<li>
<div>If you have to pass a parameter, you can enter it in the command text like this:</div>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2010/05/050410_1802_RunningaSQL9.png" alt="" /></p>
<p> </li>
<li>If you have to pass dynamic parameters you'll have to turn to VBA. I'll do a post on this later this week.</li>
<li>I assume you can do this with ORACLE databases too.</li>
<li>I've yet to test whether this will fire a Stored Procedure that doesn't return data. In other words, Stored Procedures that perform Insert, Update or Delete actions. I assume that if you can, there is the possibility of updating SQL from Excel through a simple connection. Pretty cool.</li>
</ol>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://datapigtechnologies.com/blog/index.php/creating-a-zoom-box-in-excel/" rel="bookmark" class="crp_title">Creating a Zoom Box in Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/add-rank-to-pivottable/" rel="bookmark" class="crp_title">Add Rank to PivotTable</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/building-version-control-in-excel/" rel="bookmark" class="crp_title">Building Version Control in Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/" rel="bookmark" class="crp_title">Running an Access Parameter Query from Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/excel-2010-paste-special-commands/" rel="bookmark" class="crp_title">Excel 2010 Paste Special Commands</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running an Access Parameter Query from Excel</title>
		<link>http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/</link>
		<comments>http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 09:46:46 +0000</pubDate>
		<dc:creator>datapig</dc:creator>
				<category><![CDATA[Access Queries]]></category>
		<category><![CDATA[Excel & Access Integration]]></category>
		<category><![CDATA[Excel VBA]]></category>
		<category><![CDATA[MS Query]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Queries]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=1148</guid>
		<description><![CDATA[An Access parameter query is a kind of interactive query that prompts you for criteria before the query is run. Parameter queries are useful when you need to ask the query different questions using different criteria each time you run it.
Now we all know you can pull data from Access into Excel using MS Query. [...]]]></description>
			<content:encoded><![CDATA[<p>An Access parameter query is a kind of interactive query that prompts you for criteria before the query is run. Parameter queries are useful when you need to ask the query different questions using different criteria each time you run it.</p>
<p>Now we all know you can pull data from Access into Excel using MS Query. The problem is that MS Query doesn't let you pull in Parameter queries. There may be a technical reason for this, but I like to think it's just Microsoft's way of keeping things interesting. After all, technical roadblocks <span style="text-decoration: underline;">are</span> the spice of life.<br />
If you've had enough spice, I'll show you a VBA workaround that will enable you to run an Access parameter query from Excel.</p>
<p> <span id="more-1148"></span></p>
<p><span style="font-size:14pt"><strong>The Problem:<br />
</strong></span></p>
<p>I've built this parameter query in Accesss. This particular query will ask the user for a Region and a Business Segment. This works fine in Access.</p>
<p>I've named this query <strong>MyParameterQuery</strong>.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/10/101909_0945_RunninganAc1.png" alt="" /></p>
<p> </p>
<p>The problem is when I try to connect to this query via MS Query in Excel, I don't see it in the list. It turns out that Parameter queries are not available in list of connectable objects.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/10/101909_0945_RunninganAc2.png" alt="" /></p>
<p> </p>
<p>Even if I try to get cocky, brute forcing MS Query to look at the query, I get the dreaded "Too Few Parameters" error.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/10/101909_0945_RunninganAc3.png" alt="" /></p>
<p> </p>
<p> </p>
<p><span style="font-size:14pt"><strong>The Solution:<br />
</strong></span></p>
<p>My solution is to use a bit of VBA to pull the data based on parameters you enter directly into Excel.</p>
<p>The first step is to set up a spreadsheet like the one shown here.  You'll notice that the needed parameters will be fed from Cells D3 and D4.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/10/101909_0945_RunninganAc4.png" alt="" /></p>
<p> </p>
<p>Once your spreadsheet is ready to go, switch over to VBA and enter this code into a standard module.</p>
<p><strong>Note: </strong>You will need to add a reference to the <strong>Microsoft DAO XX Object Library</strong> (where XX represents the latest version you have) .</p>
<p> </p>
<div class="syntax_hilite">
<div id="vb-2">
<div class="vb"><span style="color: #b1b100;">Sub</span> RunParameterQuery<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></p>
<p><span style="color: #808080;">'Step 1: Declare your variables</span><br />
<span style="color: #b1b100;">Dim</span> MyDatabase <span style="color: #b1b100;">As</span> DAO.<span style="color: #b1b100;">Database</span><br />
<span style="color: #b1b100;">Dim</span> MyQueryDef <span style="color: #b1b100;">As</span> DAO.<span style="color: #b1b100;">QueryDef</span><br />
<span style="color: #b1b100;">Dim</span> MyRecordset <span style="color: #b1b100;">As</span> DAO.<span style="color: #b1b100;">Recordset</span><br />
<span style="color: #b1b100;">Dim</span> i <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Integer</span></p>
<p><span style="color: #808080;">'Step 2: Identify the database and query</span><br />
<span style="color: #b1b100;">Set</span> MyDatabase = DBEngine.<span style="color: #66cc66;">OpenDatabase</span> _<br />
<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"C:\Integration\IntegrationDatabase.accdb"</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color: #b1b100;">Set</span> MyQueryDef = MyDatabase.<span style="color: #66cc66;">QueryDefs</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"MyParameterQuery"</span><span style="color:#006600; font-weight:bold;">&#41;</span></p>
<p><span style="color: #808080;">'Step 3: Define the Parameters</span><br />
<span style="color: #b1b100;">With</span> MyQueryDef<br />
.<span style="color: #66cc66;">Parameters</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"[Enter Segment]"</span><span style="color:#006600; font-weight:bold;">&#41;</span> = Range<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"D3"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Value</span><br />
.<span style="color: #66cc66;">Parameters</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"[Enter Region]"</span><span style="color:#006600; font-weight:bold;">&#41;</span> = Range<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"D4"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Value</span><br />
<span style="color: #b1b100;">End</span> <span style="color: #b1b100;">With</span></p>
<p><span style="color: #808080;">'Step 4: Open the query</span><br />
<span style="color: #b1b100;">Set</span> MyRecordset = MyQueryDef.<span style="color: #66cc66;">OpenRecordset</span></p>
<p><span style="color: #808080;">'Step 5: Clear previous contents</span><br />
Sheets<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"Main"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Select</span><br />
ActiveSheet.<span style="color: #66cc66;">Range</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"A6:K10000"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">ClearContents</span></p>
<p><span style="color: #808080;">'Step 6: Copy the recordset to Excel</span><br />
ActiveSheet.<span style="color: #66cc66;">Range</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"A7"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">CopyFromRecordset</span> MyRecordset</p>
<p><span style="color: #808080;">'Step 7: Add column heading names to the spreadsheet</span><br />
<span style="color: #b1b100;">For</span> i = <span style="color: #cc66cc;">1</span> <span style="color: #b1b100;">To</span> MyRecordset.<span style="color: #66cc66;">Fields</span>.<span style="color: #b1b100;">Count</span><br />
ActiveSheet.<span style="color: #66cc66;">Cells</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #cc66cc;">6</span>, i<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Value</span> = MyRecordset.<span style="color: #66cc66;">Fields</span><span style="color:#006600; font-weight:bold;">&#40;</span>i - <span style="color: #cc66cc;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #b1b100;">Name</span><br />
<span style="color: #b1b100;">Next</span> i</p>
<p><span style="color: #b1b100;">MsgBox</span> <span style="color: #ff0000;">"Your Query has been Run"</span></p>
<p><span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></div>
</div>
</div>
<p></p>
<p> </p>
<p>After the code is ready, running it will make data magically appear based on your parameters!</p>
<p>Who needs MS Query?</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/10/101909_0945_RunninganAc5.png" alt="" /></p>
<p> </p>
<p>This technique allows you to build some interesting reporting solutions with relatively little effort.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://datapigtechnologies.com/blog/index.php/easily-move-access-query-results-to-excel/" rel="bookmark" class="crp_title">Easily Move Access Query Results to Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/" rel="bookmark" class="crp_title">Passing Multiple Values to One Parameter</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/sending-variable-access-data-to-an-excel-range/" rel="bookmark" class="crp_title">Sending Variable Access Data To An Excel Range</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/building-access-macros-is-a-drag/" rel="bookmark" class="crp_title">Building Access Macros is a Drag</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/creating-a-histogram-in-access/" rel="bookmark" class="crp_title">Creating a Histogram in Access</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Passing Multiple Values to One Parameter</title>
		<link>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/</link>
		<comments>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 06:05:31 +0000</pubDate>
		<dc:creator>datapig</dc:creator>
				<category><![CDATA[Excel & Access Integration]]></category>
		<category><![CDATA[MS Query]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Power Tips]]></category>

		<guid isPermaLink="false">http://datapigtechnologies.com/blog/?p=675</guid>
		<description><![CDATA[I often use MS Query to pull external data into Excel. I find it to be an extremely powerful way to quickly pull together interactive reporting without a lot of effort. If you're new to MS Query, you may want to check out Kusleika's intro to MS Query to get the gist.
.
Anyway, one of the [...]]]></description>
			<content:encoded><![CDATA[<p>I often use MS Query to pull external data into Excel. I find it to be an extremely powerful way to quickly pull together interactive reporting without a lot of effort. If you're new to MS Query, you may want to check out <a href="http://www.dicks-clicks.com/excel/ExternalData.htm" target="_blank">Kusleika's intro to MS Query</a> to get the gist.</p>
<p><span style="color: #ffffff;">.</span></p>
<p>Anyway, one of the more common requests I get is to allow a user to dynamically pass multiple criteria to a parameter. For example, a manager may want to pull in data for Tulsa, and Dallas, and Seattle at the same time.<br />
<span id="more-675"></span></p>
<p><span style="color: #ffffff;">.</span></p>
<p>In this example, I've built a model where a user can use a Multi-select Listbox to choose Markets. The MS Query responds accordingly to bring back the chosen Markets.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult1.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p>The selection of different Markets brings back another set of data.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult2.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p>What's interesting about this is that I only have one parameter built into my MS Query connection. That's right; I'm passing multiple markets to one parameter.</p>
<p>Here's how it's done:</p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>Step 1: Build a basic MS Query connection without any parameters<br />
</strong></p>
<p>Here, I've built a query that gives me all Markets.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult3.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>Step 2: Right-click anywhere inside the query table and select External Data Properties<br />
</strong></p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult4.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>Step 3: Click Connection Properties<br />
</strong></p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult5.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>Step 4: Add a WHERE clause that passes a parameter through an Instr function<br />
</strong></p>
<p>The Instr function is designed to find the occurrence of a string within another string, returning the position number for the string you are trying to find.</p>
<p>The basic syntax is Instr(String to Search, String to Find)</p>
<p>In this example, I am using <strong>Instr(?, [Market])</strong>. This will evaluate each market to see if it is found in the parameter I am passing.</p>
<p>So if I literally pass multiple markets to my parameter separated by commas, (for example; "Denver, Tulsa, California"), all matching markets will evaluate to a position number greater than zero.</p>
<p><span style="color: #ffffff;">.</span></p>
<p>The long and short of it is that a WHERE clause is added to the query that will only return records where the Market field evaluates to a position number greater than zero when thrown against my parameter. Thus:</p>
<p><strong>WHERE (Instr(?, [Market])&gt;0)<br />
</strong></p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult6.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>Step 5: Set up your parameter to use a cell reference for future refreshes<br />
</strong></p>
<p>In this example, I'm telling my query to get the parameter values from cell A1<strong><br />
</strong></p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult7.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p>Once that is set up, any value placed in Cell A1 will trigger the MS Query to refresh.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult8.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p>And because of our cool Instr function, we can request multiple markets in that one parameter.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult9.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p><span style="font-size:14pt"><strong>Setting up the Multi-Select ListBox<br />
</strong></span></p>
<p>If you want to get fancy, you can add an ActiveX Listbox and configure it to be multi-select.</p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult10.png" alt="" /></p>
<p><img src="http://datapigtechnologies.com/blog/wp-content/uploads/2009/08/080509_0605_PassingMult11.png" alt="" /></p>
<p><span style="color: #ffffff;">.</span></p>
<p>Once you have your Listbox set up, you'll have to use a bit of code to pass the selected items to cell A1 ( the trigger for the query table).</p>
<div class="syntax_hilite">
<div id="vb-4">
<div class="vb"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> ListBox1_Change<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color: #b1b100;">Dim</span> lItem <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span><br />
<span style="color: #b1b100;">Dim</span> strSelected <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span></p>
<p><span style="color: #b1b100;">For</span> lItem = <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">To</span> ListBox1.<span style="color: #66cc66;">ListCount</span> - <span style="color: #cc66cc;">1</span><br />
<span style="color: #b1b100;">If</span> ListBox1.<span style="color: #66cc66;">Selected</span><span style="color:#006600; font-weight:bold;">&#40;</span>lItem<span style="color:#006600; font-weight:bold;">&#41;</span> = <span style="color: #b1b100;">True</span> <span style="color: #b1b100;">Then</span><br />
strSelected = strSelected &amp; ListBox1.<span style="color: #66cc66;">List</span><span style="color:#006600; font-weight:bold;">&#40;</span>lItem<span style="color:#006600; font-weight:bold;">&#41;</span> &amp; <span style="color: #ff0000;">", "</span><br />
<span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span><br />
<span style="color: #b1b100;">Next</span> lItem</p>
<p><span style="color: #808080;">'Update the trigger cell</span><br />
Range<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"A1"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Value</span> = strSelected</p>
<p><span style="color: #808080;">'Refresh the query table</span><br />
ActiveSheet.<span style="color: #66cc66;">QueryTables</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">"Query from MS Access Database"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #66cc66;">Refresh</span> <span style="color: #b1b100;">False</span></p>
<p><span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></div>
</div>
</div>
<p></p>
<p><span style="color: #ffffff;">.</span></p>
<p><span style="font-size:14pt"><strong>Excel 2003</strong></span></p>
<p>You’ll notice that I’ve conspicuously not mentioned Excel 2003 yet.  Well this technique gets complicated in Excel 2003 - for a few reasons.</p>
<p>First, there is no easy way to change the SQL statement after the MS Query is built in Excel 2003.  You can do it via VBA, but it’s not practical enough to try to describe it here.</p>
<p>Second, MS Query has a conniption when you try to add the fancy Instr parameter in the MS Query Interface.  I’ve only been able to apply this technique by changing the SQL outside of MS Query.</p>
<p>Hopefully someone will suggest some obvious solution for Excel 2003 that I haven’t been able to find.</p>
<p><span style="color: #ffffff;">.</span></p>
<p><strong>*****UPDATE*****</strong></p>
<p>Dick Kusleika and Jan Karl Pieterse developed an add-in that enables the editing of SQL statements in Excel 2003!  You can get it at <a onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.jkp-ads.com');" rel="nofollow" href="http://www.jkp-ads.com/download.asp">http://www.jkp-ads.com/download.asp</a>.  The add-in is called QueryManager.  With this add-in, you can employ this technique without fighting MSQuery.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://datapigtechnologies.com/blog/index.php/easily-move-access-query-results-to-excel/" rel="bookmark" class="crp_title">Easily Move Access Query Results to Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/running-an-access-parameter-query-from-excel/" rel="bookmark" class="crp_title">Running an Access Parameter Query from Excel</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/find-and-replace-generally-sucks-in-access/" rel="bookmark" class="crp_title">Replacing Large Amounts of Data in Access</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/special-characters-are-a-pain-in-the-asterisk/" rel="bookmark" class="crp_title">Special Characters are a Pain in the Asterisk</a></li><li><a href="http://datapigtechnologies.com/blog/index.php/show-a-progress-meter-in-the-status-bar/" rel="bookmark" class="crp_title">Show a Progress Meter in the Status Bar</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://datapigtechnologies.com/blog/index.php/passing-multiple-values-to-one-parameter/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
