Converting String to Date

S

Scott

I'm getting a type mismatch below because "myDateVar" is a string type. How
can I convert "myDateVar" to a date type, so my SQL statement will test
coorectly and find a record if it has a dtDate field equal to 5/7/2006?

The t_data table is a sql ntable and dtDate is datetime type.

CODE **********

myDateVar = "20060507" ' string type

Dim objRS2 As ADODB.Recordset

Set objRS2 = New ADODB.Recordset
objRS2.ActiveConnection = CurrentProject.Connection
objRS2.CursorType = adOpenStatic
objRS2.Open "SELECT * from t_data WHERE dtDate = " & "'" & myDateVar &
"'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top