OLE DB Query Command Text

RaviWildcat

Board Regular
Joined
Jun 18, 2010
Messages
119
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello everyone!

I've just started playing with importing data into excel from an access database using Data / From Access / and then selecting a table.

I can even edit the query by right on the data returned, clicking on Table, Edit Query and playing with the command text.

So - my OLE DB Query Command text can look like:

select blah from blah

My question is - is there a way to embed a variable in the command text? I'm hoping to create another worksheet with values and then name one of the cells as a variable, and then use that variable in the query of the OLE DB Query command text

So, if I have another worksheet and in cell $a$1 I insert the date 11/30/2010 and name that 'pull_date'

I'd like to use that variable in OLD DB Query command text as

select blah from blah where blah = %pull_date%

I can use any number of formulas once I have the data pulled in from my access db, but I'm wondering if there's a fun way to play with the query in the query definition?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Parameterized Queries are supported by MSQuery:
http://www.dailydoseofexcel.com/archives/2004/12/13/
http://www.tushar-mehta.com/excel/newsgroups/rdbms_in_excel/index.html (queries 4 and 5)
http://www.dicks-clicks.com/excel/ExternalData6.htm#Parameters
http://office.microsoft.com/en-us/excel-help/customize-a-parameter-query-HP010216113.aspx

You will notice that when you create a parameter Excel will put a question mark in the SQL command text - so that usually works too, if you like to edit the SQL directly. I should give it a try with the parameters button. Though in Excel 2007/2010 offhand I'm not sure how all the menus have been re-arranged.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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