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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA/SQL handling of dates

Status
Not open for further replies.

Klara

Technical User
Dec 28, 2001
1
US
Hi, I have the following code:

curve = Forms!frm_YldCurve!YCType.Value
yc_date = Forms!frm_YldCurve!YCDate.Value
...
With CurrentDb.OpenRecordset("SELECT AllYldCrvs.YCType, AllYldCrvs.YCDate FROM AllYldCrvs WHERE (((AllYldCrvs.YCType)=""&curve&"") AND ((AllYldCrvs.YCDate)=""& yc_date &""))", dbOpenDynaset)

curve is a text variable
yc_date holds a date value in the MM/DD/YYYY format
my code substitutes yc_date as one of the parameters in the SQL query above

This code doesn't work :( - I get a "type mismatch" error for yc_date. I suspect that I need to add a few more quotation marks or parentheses or pound signs or something else around the variable name, but can't find any references telling me exactly what to do. If anyone knows how I should change the syntax, I would really appreciate any tips you could provide.
 
it looks like there are too many quotation marks? also if YCType is text, then there needs to be SINGLE quotes around it (embedded in the double-quotes that designated the sql statement) and for the date, try putting # around the date (that designates a date type). not sure if this is perfect so you might have to still goof around with it:

With CurrentDb.OpenRecordset("SELECT AllYldCrvs.YCType, AllYldCrvs.YCDate FROM AllYldCrvs
WHERE AllYldCrvs.YCType='" & curve & "' AND AllYldCrvs.YCDate = #" & yc_date &"#", dbOpenDynaset)

so it ends up:

WHERE AllYldCrvs.YCType = 'XType' AND AllYldCrvs.YCDate = #07/23/2001#

hope this helps.
g

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top