virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
Private Sub Command4_Click()
Form1.Text1.Text = DataGrid1.Columns(9).Text
Form1.Show
Form27.Hide
End Sub

If this code is written then how can i get the grand total of all the grids
make a control array of grids and add the totals of each one of them to get the
desired total

p.s. you have 2 different programs its better to split them into different threads not all together.
you make everyone confused.

Last edited by virxen; 30Aug2010 at 02:29..
viv345's Avatar, Join Date: Feb 2010
Contributor
Sorry!
It is all in one program. But every form contains different labels, datagrid and commands. I have tried to make it more simple. I am attaching the Project in zip. Now in this only one form contains two data grid. And each form I have used option buttons for calculation and One command button to get the Total from the grid into the text box. After getting the totals from each form in a Text box, their is a Summary button to go to the Summary form. In Summary form their are also a option buttons and text boxes and one command button GET to collect the totals into the text boxes.

It is all in one program. But every form contains different labels, datagrid and commands. I have tried to make it more simple. I am attaching the Project in zip.

My previous project long and confusing. It was not only confusing me but also the others.

So now i have altered my project into simple one. No confusions.

The problem is same to get Total of all data entered into Data Grid into a text box by click the command Total. In form 16 to get the totals by selecting option buttons.
Attached Images
File Type: jpg 1p.jpg (67.7 KB, 3 views)
File Type: jpg 2p.jpg (54.8 KB, 2 views)
Attached Files
File Type: zip project.zip (181.4 KB, 5 views)

Last edited by virxen; 31Aug2010 at 02:50..
virxen's Avatar, Join Date: Nov 2009
Pro contributor
why do you use so many databases?
use only one with many tables its better approach.
viv345 like this
viv345's Avatar, Join Date: Feb 2010
Contributor
just to avoid big size files.

O. K. I will try to make it one?

Last edited by virxen; 31Aug2010 at 02:50..
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
just to avoid big size files.

O. K. I will try to make it one?
1) all your forms (except form1) must have this code
Code:
Private Sub Form_Unload(Cancel As Integer)
Rs.Close
conn.Close
Form1.Visible = True
End Sub
because if you close one of yours forms you see nothing.The control must be returned
to form1.

2)
Quote:
Private Sub Form2_Unload()
Rs.Close
conn.Close
End Sub
this is wrong,the correct name is form_Unload regardless of form's name(for example form2)

3) try using names for your forms and controls to make your code readable.
you have 8 forms form1,.. form16. Make use of the (name) property to give names to help you in programming
for example text2 is better or txtRate?

you can use the first 3 letters to indicate what this control is and then a name with a meaning starting with a capital letter.
txt=textbox
frm=form
lbl=label
cmd=command button
opt=option button
cmb=combo box
and so on
for example frmPhotostat is better than just form2!


4)

Quote:
Originally Posted by virxen View Post
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)
Code:
 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
..............

in this post was the answer for your first question did you notice?
just change your code to look like this in form2

Code:
Private Sub Command10_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(2).Text)
    Adodc1.Recordset.MoveNext
Next
Text32.Text = CStr(a)
Adodc1.Recordset.MoveFirst 'gets the header to first record (selects the first row)
End Sub

and finally i will answer your second question when you post again your project with the changes,and all totals working okay according to the above.

p.s. your project with only one database is here
Attached Files
File Type: rar project.rar (47.6 KB, 4 views)

Last edited by virxen; 31Aug2010 at 03:31..
viv345's Avatar, Join Date: Feb 2010
Contributor
Can i create new database using coding. If yes then How?
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
Can i create new database using coding. If yes then How?
database or database table you mean?
viv345's Avatar, Join Date: Feb 2010
Contributor
db file with table
viv345's Avatar, Join Date: Feb 2010
Contributor
getting problem in calculating row by row?
Project attached
Attached Files
File Type: zip income.zip (28.4 KB, 3 views)
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Quote:
Originally Posted by viv345 View Post
db file with table

see here
http://p2p.wrox.com/pro-vb-6/6605-ho...-vb6-code.html
viv345 like this