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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
William ElliottConnect With a Mentor Sr 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
 
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
All Courses

From novice to tech pro — start learning today.