error in date between query

asifbhura
04-14-2004, 11:48 PM
hI everyone

Using Ms access

I want to display records in datagrid where records must be in selected date by combobox

i tried it like given code

but it displays only selected of second combobox
private sub commnad1_click
Dim myDate1 As Date
Dim myDate2 As Date
Dim sSQL As String
myDate1 = CDate(Combo2.Text)
myDate2 = CDate(Combo3.Text)

sSQL = "SELECT * FROM costtable WHERE [Date] BETWEEN #" & myDate1 & "# AND #" & myDate2 & "#"

rs2.Open sSQL, cn, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = rs2
DataGrid1.Refresh

using this query it displays records in datagrid which selected by combo3

i want all records between selected two date.

Please help me its kind urgent

Waiting and hoping for favorable reply.

Thanx a lot

manivbforum
04-15-2004, 12:42 AM
Ty this if db is sqlserver
sSQL = "select * from costtable where date between convert(datetime,'" & myDate1 & "') and convert(datetime,'" & myDate2 & "')"

note: Its better avoid date as a column name.

hI everyone

I want to display records in datagrid where records must be in selected date by combobox

i tried it like given code

but it displays only selected of second combobox
private sub commnad1_click
Dim myDate1 As Date
Dim myDate2 As Date
Dim sSQL As String
myDate1 = CDate(Combo2.Text)
myDate2 = CDate(Combo3.Text)

sSQL = "SELECT * FROM costtable WHERE [Date] BETWEEN #" & myDate1 & "# AND #" & myDate2 & "#"

rs2.Open sSQL, cn, adOpenDynamic, adLockOptimistic

Set DataGrid1.DataSource = rs2
DataGrid1.Refresh

using this query it displays records in datagrid which selected by combo3

i want all records between selected two date.

Please help me its kind urgent

Waiting and hoping for favorable reply.

Thanx a lot

MKoslof
04-15-2004, 06:49 AM
Are you using Access or SQL Server for this? If this is Access your query is fine. If using SQL Server let me know and we'll modify it. What exactly is not working?

And there is no reason to refresh the DataGrid after setting the datasource. And note, if you are running this query consistenly you need to re-bind the Grid Datasource each time. So, if you run this query three times in a row, each time you need to set the Grid = Nothing and rebind the new returned recordset. You are dealing with a bound control here....

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum