
Update datagrid recordset and 1 summary textbox field
Hi, all
I have 1datagrid to display some order details and 1 textbox field to
display the summary of order details.
What I need is : immediately after the user update the datagrid cell ( that
is , after update the field , not after update the record),
I can update the display of sum. so I add the code " ors.update" in the
"oRs_FieldChangeComplete" procedure. But it always raise error.
So,
How can I calculate the summary ?
Can the calculate be done in a more efficiently or simpler way?
Could somebody help me? Thanks in advance.
Karen
---My code---------------------
Dim oConn As ADODB.Connection
Dim WithEvents oRs As ADODB.Recordset
Dim intSum As Long
Private Sub Form_Load()
' Open a new connection
Set oConn = New ADODB.Connection
oConn.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=C:\Program Files\Microsoft Visual
Studio\VB98\Nwind.mdb;"
' Open up a recordset for datagrid
Set oRs = New ADODB.Recordset
With oRs
.CursorLocation = adUseClient
.Open "select OrderID,ProductID,Quantity from [Order Details] where
orderid = 11070", oConn, _
adOpenStatic, adLockOptimistic, adCmdText
End With
Set grdDataGrid.DataSource = oRs
With oRs
'calculate the total
intSum = 0
Do While Not oRs.EOF
intSum = intSum + oRs.Fields("Quantity").Value
.MoveNext
Loop
Debug.Print intSum
End With
End Sub
Private Sub oRs_FieldChangeComplete(ByVal cFields As Long, ByVal Fields As
Variant, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
oRs.Update 'will generate error
'oRs.UpdateBatch 'will generate error
With oRs
'calculate the total
Debug.Print oRs.Fields("Quantity").Value
intSum = 0
oRs.MoveFirst
Do While Not oRs.EOF
intSum = intSum + oRs.Fields("Quantity").Value
.MoveNext
Loop
Debug.Print intSum
'MsgBox intSum
End With
End Sub