Need to query access database with date range

I need to be able to query a database based on three different fields. Two text fields and one date/time field.
The query returns records when i leave out the date but when added no  records are returned.
The following code works correctly. But now i need to check if  the field "updated" value is >= sDate and <= eDate






Thanks In Advance
'Get start and end dates from to dateTimePickers
sDate = dateStart.Value.Date
eDate = dateEnd.Value.Date
 
 
sql = "select * from mainTable where repNumber=" & _
repNum & " And Stage ='" & cboStage.SelectedItem & "'"
 
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "main")

Open in new window

packman25Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

William ElliottSr Tech GuruCommented:
what does this return?
'Get start and end dates from to dateTimePickers
sDate = dateStart.Value.Date
eDate = dateEnd.Value.Date
 
 
sql = "select * from mainTable " & _
		" where repNumber=" & repNum & _
		" And Stage ='" & cboStage.SelectedItem & "'" & _
		" And updated >='" & sDate & "'" & _
		" And updated <='" & eDate & "'"
 
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "main")

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
packman25Author Commented:
I get the error:  
Data type mismatch in criteria expression.
0
William ElliottSr Tech GuruCommented:
what happens if you manually type a date in?
chances are the the date needs to be formatted.

you will need to test it with an actual date, then make the variables produce the date in the same format.
0
packman25Author Commented:
i had to manually add the #'s

sql = "select * from mainTable " & _
        " where repNumber=" & repNum & _
        " And Stage ='" & cboStage.SelectedItem & "'" & _
         " And updated >=#" & sDate & "#" & _
        " And updated <=#" & eDate & "#"

Open in new window

0
William ElliottSr Tech GuruCommented:
cool,.. i knew it had to be something simple :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.