date order and counter

hi im a beginner of a vb6. my problem is, how i will going to arrange the date in descending format in using SQL format and how i will going to make a counter. this is my code but my SQL in Search doenst work as well as in my counter. anybody can help me.

Private Sub cmdSearch_Click()
Dim total As Currency

On Error GoTo abortsub

Set SH = Dbase.OpenRecordset("Select * from SalesHolder where Date <= ' " & DTPicker1.Value And Date >= DTPicker2.Value & " ' Order by Date")
SH.MoveFirst
Do Until SH.EOF
If DTPicker1.Value <= SH!Date And _
DTPicker2.Value >= SH!Date Then 'Exit Do
With grd
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = SH!TransCode
.TextMatrix(.Rows - 1, 1) = SH!Date
.TextMatrix(.Rows - 1, 2) = Format((SH!Amount), "##.00")
End With
total = total + grd.TextMatrix(grd.Rows - 1, 2)
End If
SH.MoveNext
Loop

grd.Rows = grd.Rows + 1
grd.TextMatrix(grd.Rows - 1, 0) = "Total"
grd.TextMatrix(grd.Rows - 1, 2) = Format(total, "#,##0.00")

abortsub:
Exit Sub
End Sub

======================================

couter

'For i = 1 To grd.Rows - 1
'STK.MoveFirst
'Do Until STK.EOF
'If trans_no = STK!ProdCode Then
' With STK
'.Edit
'!ProdCode = grd.TextMatrix(i, 0)
' !ProdName = grd.TextMatrix(i, 2)
' !Quantity = grd.TextMatrix(i, 3)
' !Date = DTPicker1.Value
' .Update
' End With
' Else
'With STK
'.Edit
'!ProdCode = grd.TextMatrix(i, 0)
'!ProdName = grd.TextMatrix(i, 2)
'!Quantity = STK!Quantity + Val(grd.TextMatrix(i, 3))
'!Date = DTPicker1.Value
'.Update
' End With
'End If
'STK.MoveNext
' Loop
'Next i


Comments

  • The SQL statement should be like this:

    Set SH = Dbase.OpenRecordset("Select * from SalesHolder where Date <= CDate('" & CStr(DTPicker1.Value) & "') And Date >= CDate('" & DTPicker2.Value & "') Order by Date Desc")

    also try to change the name of the 'Date' column to something else, for example to 'cDate', 'Date' is a preserved word in SQL
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion