Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference a date variable in SQL string

Status
Not open for further replies.

BeeDeeBee

Programmer
Dec 18, 2000
5
US
Does anyone know how to reference a variable to be interpreted as a date in an SQL string. I keep getting a "type mismatch" error. I know the field, usdatabase.TransactionDate will accept only dates.
I have tried substituting the &'s in the sevenyearsago variable with #, and it doesn't work.
Here are the relevant 2 lines of code:

sevenyearsago=DateAdd("m",-84,now)

sqlSTR=&quot;DELETE usdatabase.*, usdatabase.TransactionDate FROM usdatabase WHERE usdatabase.TransactionDate < '&quot;&amp;sevenyearsago&amp;&quot;'&quot;
Any help will be more than appreciated.


 
I finally figured it out. In case anyone else has this same question, the answer is to surround the variable with #, instead of ' e.g., as in my situation:
#&quot;&amp;sevenyearsago&amp;&quot;#&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top