Update datagrid recordset and 1 summary textbox field 
Author Message
 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



Fri, 18 Apr 2003 16:40:05 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Updating field in form from summary value in another

2. Updating textbox via code not updating recordset

3. Query Recordset, Create Summary/New Recordset

4. Strange DataGrid/Textbox update

5. Strange DataGrid/Textbox update

6. Update Record Selected From DataGrid into TextBox

7. Datagrid & recordset-update

8. Updating recordset from datagrid

9. DataGrid Update, with different recordsets

10. Datagrid & recordset-update

11. Updating Recordset with Datagrid

12. Updating an ADO recordset from user-changed data in DataGrid

 

 
Powered by phpBB® Forum Software