another 5 min job gone south
I have a 2k3 Access mdb file and attempting to use 2k8 VB Express to pick up a weeks worth of data starting on Mondays using an SQL statement. My first instinct was to use:
idate >= daStart AND idate <= daEnd
then looking at SQL examples tried:
idate BETWEEN daStart AND daEnd
neither of these appear to do anything
idate is defined as a DATE/TIME field in Access so I explicitly converted every date value using DateValue() which is supposed to return the date part and time as 00:00:00
Where am I going wrong???
----------------------------------
Dim inOffset As Long
Dim daStart as Date
Dim DaEnd as Date
Dim chSelect As String
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=T:\data.mdb")
inOffset = -1 * ((Weekday(Today) + 5) Mod 7)
' 1 2 3 4 5 6 7 1 2 3 4 5 6 7
' s m t w t f s s m t w t f s
' 6 0 1 2 3 4 5
daStart = DateValue(DateAdd(DateInterval.Day, inOffset, Today))
daEnd = DateValue(DateAdd(DateInterval.Day, 6, daStart))
=
chSelect = "Select idate, ref, desc FROM item WHERE ccode = 'ABC' AND datevalue(idate) between " & daStart & " AND " & DaEnd
Dim cmd As OleDbCommand = New OleDbCommand(chSelect, con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
con.Close()
con = Nothing
I have a 2k3 Access mdb file and attempting to use 2k8 VB Express to pick up a weeks worth of data starting on Mondays using an SQL statement. My first instinct was to use:
idate >= daStart AND idate <= daEnd
then looking at SQL examples tried:
idate BETWEEN daStart AND daEnd
neither of these appear to do anything
idate is defined as a DATE/TIME field in Access so I explicitly converted every date value using DateValue() which is supposed to return the date part and time as 00:00:00
Where am I going wrong???
----------------------------------
Dim inOffset As Long
Dim daStart as Date
Dim DaEnd as Date
Dim chSelect As String
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=T:\data.mdb")
inOffset = -1 * ((Weekday(Today) + 5) Mod 7)
' 1 2 3 4 5 6 7 1 2 3 4 5 6 7
' s m t w t f s s m t w t f s
' 6 0 1 2 3 4 5
daStart = DateValue(DateAdd(DateInterval.Day, inOffset, Today))
daEnd = DateValue(DateAdd(DateInterval.Day, 6, daStart))
=
chSelect = "Select idate, ref, desc FROM item WHERE ccode = 'ABC' AND datevalue(idate) between " & daStart & " AND " & DaEnd
Dim cmd As OleDbCommand = New OleDbCommand(chSelect, con)
con.Open()
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
con.Close()
con = Nothing