# Help with ODBC Query for VBA

**URL:** <https://boards.straightdope.com/t/help-with-odbc-query-for-vba/51322>\
**Category:** Factual Questions\
**Created:** [January 22, 2001, 10:25pm UTC](https://boards.straightdope.com/t/help-with-odbc-query-for-vba/51322 "2001-01-22T22:25:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tretiak](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@Tretiak](https://boards.straightdope.com/u/Tretiak)\
**Post date:** [January 22, 2001, 10:25pm UTC](https://boards.straightdope.com/t/help-with-odbc-query-for-vba/51322/1 "2001-01-22T22:25:32Z")

</div>

This is probably easy but I am having the toughest time.

I am wiritn an EXCEL macro that will access an Oracle Database. I need to filter through a field in date format. If I were explicit with the date I would simple have…

Select TABLE.MYDATA\_VALUE  
From TABLE  
Where TABLE.MYDATA\_DATE = {ts ‘2001-01-21 00:00:00’}

However, in the macro the date is not explicit, but would be entered upon prompting. So if it is stored, let’s say in , TheDate, how would I rewrite the above. Am I making any sense?

---

<div class="post-metadata">

**Author:** ![Baraqiyal](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@Baraqiyal](https://boards.straightdope.com/u/Baraqiyal)\
**Post date:** [January 23, 2001, 12:13am UTC](https://boards.straightdope.com/t/help-with-odbc-query-for-vba/51322/2 "2001-01-23T00:13:41Z")

</div>

Here’s my best guess:

sql = "Select TABLE.MYDATA\_VALUE "  
sql = sql & "From TABLE "  
sql = sql & “Where TABLE.MYDATA\_DATE = {ts '” & TheDate & “’}”
