virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
Sir
And code given for calculating column what i do if i had to calculate Rows
Code:
Private Sub calcRow_Click()
Dim i, a As Integer
a = 0
'Iteration for col by col for selected row
For i = 0 To Adodc1.Recordset.Fields.Count - 2
    'Calculate the result
    a = a + Val(DataGrid1.Columns(i).Text)
Next
MsgBox "result=" + CStr(a)
End Sub
viv345 like this
viv345's Avatar, Join Date: Feb 2010
Contributor
yes database is properly connected with Adodc1
viv345's Avatar, Join Date: Feb 2010
Contributor
I tried it there were some mistakes I have made in the codings now it is working.
THANKS!

What I do if I want all the datagrid columns Total in another as an Summary of all?

How can I display the TOTALS of All data grid.

Last edited by virxen; 16Aug2010 at 03:02..
viv345's Avatar, Join Date: Feb 2010
Contributor
Sir,
One more thing I made a Invoice Report. In which when I want to delete the data it gives error. Can you pl. check whats wrong.
Attached Images
File Type: jpg 1.jpg (46.7 KB, 2 views)
File Type: jpg 1 (1).jpg (61.5 KB, 2 views)
Attached Files
File Type: zip Invoice.zip (97.5 KB, 5 views)
viv345's Avatar, Join Date: Feb 2010
Contributor
One more thing When I use this code:-
Private Sub cmdTotalGrid_Click()
Dim i, a As Integer
a = 0
Adodc1.Recordset.MoveFirst 'Move the record position to the first
'Iteration for row by row
For i = 1 To Adodc1.Recordset.RecordCount
'Calculate the result
a = a + Val(DataGrid1.Columns(9).Text)
Adodc1.Recordset.MoveNext
Next
MsgBox "result=" + CStr(a)
End Sub

It gives error in

Private Sub cmddelete_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Else
MsgBox "no record found"
End If
End Sub


Saying either BOF or EOF is true , or the
current record has been deleted.
Requested operation requires a current record.
Attached Images
File Type: jpg ScreenShot001.jpg (14.2 KB, 2 views)
File Type: jpg ScreenShot002.jpg (9.9 KB, 1 views)
viv345's Avatar, Join Date: Feb 2010
Contributor
One more thing When I use this code:-
Private Sub cmdTotalGrid_Click()
Dim i, a As Integer
a = 0
Adodc1.Recordset.MoveFirst 'Move the record position to the first
'Iteration for row by row
For i = 1 To Adodc1.Recordset.RecordCount
'Calculate the result
a = a + Val(DataGrid1.Columns(9).Text)
Adodc1.Recordset.MoveNext
Next
MsgBox "result=" + CStr(a)
End Sub

It gives error in

Private Sub cmddelete_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Else
MsgBox "no record found"
End If
End Sub


Saying either BOF or EOF is true , or the
current record has been deleted.
Requested operation requires a current record.
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
Sir,
One more thing I made a Invoice Report. In which when I want to delete the data it gives error. Can you pl. check whats wrong.
Code:
Private Sub cmdDelete_Click()
If rec.RecordCount > 0 Then
rec.Delete
Else
MsgBox "NO RECORD FOUND"
End If
End Sub
its not adodc here
shabbir, viv345 likes this
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
One more thing When I use this code:-
Private Sub cmdTotalGrid_Click()
Dim i, a As Integer
a = 0
Adodc1.Recordset.MoveFirst 'Move the record position to the first
'Iteration for row by row
For i = 1 To Adodc1.Recordset.RecordCount
'Calculate the result
a = a + Val(DataGrid1.Columns(9).Text)
Adodc1.Recordset.MoveNext
Next
MsgBox "result=" + CStr(a)
End Sub

It gives error in

Private Sub cmddelete_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Else
MsgBox "no record found"
End If
End Sub


Saying either BOF or EOF is true , or the
current record has been deleted.
Requested operation requires a current record.

if you see the datagrid after the execution of cmdTotalGrid_click you will notice
that there is no selected row.So by executing delete or calcRowTotal you will
have an error produced.

there are 2 solutions.

1)
Code:
Private Sub cmdTotalGrid_Click()
Dim i, a As Integer
a = 0
Adodc1.Recordset.MoveFirst 'Move the record position to the first
'Iteration for row by row
For i = 1 To Adodc1.Recordset.RecordCount
    'Calculate the result
    a = a + Val(DataGrid1.Columns(9).Text)
    Adodc1.Recordset.MoveNext
Next
MsgBox "result=" + CStr(a)
Adodc1.Recordset.MoveFirst'gets the header to first record (selects the first row)

End Sub
2) check before you act
Code:
Private Sub cmddelete_Click() 'delete button
If Adodc1.Recordset.RecordCount <= 0 Then
MsgBox "no record found"
Exit Sub
End If
If Adodc1.Recordset.BOF = True Or Adodc1.Recordset.EOF = True Then
MsgBox "no record selected"
exit sub
End If'with this you check if a row(record) is selected
..............
shabbir, viv345 likes this
viv345's Avatar, Join Date: Feb 2010
Contributor
THANKS

Now their is one more problem or you can say my imagination i.e.

I want to display the Datagrid Total in Separate form as an SUMMARY.

How should I code for that?

Same as we take the time calculation project when we click on calculate datagrid it gives result =10 I want this [THIS RESULT = 10] in separate form.

Timecal.zip attached
Attached Files
File Type: zip Time Cal.zip (27.5 KB, 9 views)

Last edited by virxen; 17Aug2010 at 02:31..
virxen's Avatar, Join Date: Nov 2009
Pro contributor
you have 2 forms in your project
1) both will be visible at the same time?if not how will the second form become visible?pressing a command button for example?

2)the second form will be informed immediately with the changes or you must press a button?

3)why you use adodc in second form?

4)in second form you have add and delete button.why?since this form is only
for the results?
viv345 like this