1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Time calculation add/delete in data grid getting problem

Discussion in 'Visual Basic ( VB )' started by viv345, Aug 9, 2010.

  1. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    1) No one form (Form 27) will be visible and to go for second form (Form1) GO command key is pressed.
    2) The second form we can do any thing
    a) either form will be informed immediately after every change it will be nice than i have not click the text button to get the result;
    b) or I can click the text button to get the result from Form (Form 27)
    3) In second form I have used Adodc to display/add the results of whole day/week/month in Data Grid
    4) In second form I have used add and delete button so that i can add[B/ the result in Data Grid and Delete Button for deleting data from Data Grid after whole day/month/week so that I can know the SUMMARY of a day/month/week.
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    1) try this instead

    form27
    Code:
    Private Sub Command4_Click() 'GoBack button
    Form1.Show
    Form27.[COLOR=Red]Hide[/COLOR]
    End Sub
    
    form1
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    conn.Close
    Form27.Show
    Form1.Hide
    End Sub
    
     
    viv345 and shabbir like this.
  3. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Shabbir

    How can I get the Results in Form No. 1?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,314
    Likes Received:
    372
    Trophy Points:
    83
    Many ways and one of them is by accessing variables
     
    viv345 likes this.
  5. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
  6. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    first of all correct your errors ,for example
    Code:
    Private Sub Text8_Click()
    If [COLOR=Red]Text4.Text = 1[/COLOR] Then'the correct is if val(Text4.text)=1 then
     [COLOR=Red]Text8.Text = 1 * 10#[/COLOR]'....=Cstr(1*10#)
     End If
    If [COLOR=Red]Text4.Text = 2[/COLOR] Then
       [COLOR=Red]Text8.Text = 2 * 10#[/COLOR]
     End If
     If [COLOR=Red]Text4.Text = 0[/COLOR] Then
     Text8.Text = "0"
     End If
       End Sub
    
    
    and now for your question

    change the code in your project with this and see how is done


    form27
    Code:
    Private Sub Command4_Click() 'GoBack button
    [COLOR=Red]Form1.Text1.Text[/COLOR] = "i was sent by form27!!!"
    Form1.Show
    Form27.Hide
    End Sub
    
    you access a value of an object following its path(where it belongs)

    now try it alone and if you get stacked post again.
     
    Last edited: Aug 19, 2010
    viv345 and shabbir like this.
  7. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Tried but it is not taking the total. I have added two entries. The total comes 20 but it takes only one entry.

    Project attached
     

    Attached Files:

  8. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    your code is only passing the value of field10 of the current selected record.

    if i understand correctly what you want to do,i think you should use sql queries.

    open ms access
    create a new query--->query1 for example
    goto sql view and write

    Code:
    SELECT DISTINCT field1, sum(field10) as field2
    FROM Table1
    GROUP BY field1;
    
    save and exit ms access.

    now go to your vb project

    go to form1-->go to adodc1 properties-->go to recordsource tab
    in table or stored procedure name-->select query1-->ok

    now go to datagrid1,right click and retrieve fields.

    when you press go button
    Code:
    Private Sub Command4_Click() 'GoBack button
    Form1.Show
    Form27.Visible = False
    End Sub
    
    you will see the datagrid1 filled automatically with the values you want.

    if something is not working as you want tell me.


    p.s. table2 is not used
     
    viv345 and shabbir like this.
  9. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    I tried it works. THANKS!

    My next query is if their are two data grid in one form. What sql code will be written?
     
  10. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Trial.zip attached
     

    Attached Files:

  11. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    query1
    ==============
    Code:
    SELECT DISTINCT date AS [COLOR=Red]field1[/COLOR], sum([Total Amt]) AS [COLOR=Red]field2[/COLOR]
    FROM Table1
    GROUP BY date;
    
    notice that field1,field2 are the labels of datagrid columns


    query2
    ================
    Code:
    SELECT DISTINCT [COLOR=Blue]date[/COLOR] AS field1, sum([COLOR=Blue][Total Amt][/COLOR]) AS field2
    FROM [COLOR=Blue]Table2[/COLOR]
    GROUP BY [COLOR=Blue]date[/COLOR];
    
    change your queries and try again



    p.s. you do not need second database(db27) change in form31 the properties of
    adodc1 to use as database the db1.
     
    Last edited: Aug 23, 2010
    viv345 and shabbir like this.
  12. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Sir Should I create two data grid in form 31.
     
  13. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    it depends on what you are planning to do
     
    viv345 likes this.
  14. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Sir,
    I want both data grid total in one data grid. But by making two sql queries i have to create two data grids. How can calculate two grid query in one?
     
  15. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    If following Code is written:-
    Private Sub Command4_Click() 'GoBack button
    Form1.Text1.Text = "i was sent by form27!!!"
    Form1.Show
    Form27.Hide
    End Sub

    How I can I get the Total value entered in All Grids
     
  16. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    one of the many ways is this

    Code:
    Private Sub Command1_Click()
    On Error Resume Next
    conn.Execute "drop table table3"
    conn.Execute "drop table table4"
    conn.Execute "SELECT DISTINCT table2.Date AS dates, Sum(table2.[total amt]) AS sums INTO table3 From table2 GROUP BY table2.Date;"
    conn.Execute "SELECT DISTINCT table1.Date AS dates, Sum(table1.[total amt]) AS sums INTO table4 From table1 GROUP BY table1.Date;"
    conn.Execute "INSERT INTO table3 ( dates, sums ) SELECT dates, sums FROM table4;"
    conn.Execute "drop table table4"
    conn.Execute "SELECT DISTINCT table3.Dates AS dates, Sum(table3.sums) AS sums INTO table4 From table3 GROUP BY table3.Dates;"
    conn.Ececute "drop table table3"
    conn.Close
    conn.Open
    Form31.Show
    Form2.Visible = False
    End Sub
    
    and in form31 change adodc1 properties(see picture)
     

    Attached Files:

    viv345 and shabbir like this.
  17. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Private Sub Command4_Click() 'GoBack button
    Form1.Text1.Text = "i was sent by form27!!!"
    Form1.Show
    Form27.Hide
    End Sub

    If this code is written then how can i get the grand total of all the grids
     
  18. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    I tried this code but the Table 4 is blank and not giving the results in Form 31.
     
  19. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    you do something wrong check this
     

    Attached Files:

    shabbir likes this.
  20. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page