Results 1 to 12 of 12

Thread: [RESOLVED] mshflexgrid refresh help

  1. #1

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Resolved [RESOLVED] mshflexgrid refresh help

    hi all
    my problem is how to make mshflexgrid refresh when I delete records ?
    here are code in a form delete event:
    VB Code:
    1. Private Sub cmdDelete_Click()
    2. Dim msql As String
    3. Dim Delete As String
    4.     con_cashreg.BeginTrans
    5.     Delete = MsgBox("Are you really to delete???", vbYesNo + vbCritical, "Delete")
    6.     If Delete = vbYes Then
    7.         msql = "delete * from invoicedetail"
    8.         con_cashreg.Execute (msql)
    9.         con_cashreg.CommitTrans
    10.     Else
    11.         con_cashreg.CommitTrans
    12.     End If
    13. End Sub
    I really appreciate if anyone can help me
    thanks and happy new year 2007

  2. #2

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: mshflexgrid refresh help

    I try this so far :
    VB Code:
    1. mshflexgrid.refresh
    but nothing happen to the grid

    thanks

  3. #3

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: mshflexgrid refresh help

    additional information,
    in form load I populate mshflexgrid like this:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim msql As String
    3. Me.WindowState = 2
    4.        
    5.        Label1.Caption = GetSetting(App.EXEName, "CoName", "txtco", "")
    6.        Label2.Caption = GetSetting(App.EXEName, "CoAdd", "txtAdd", "")
    7.        Label3.Caption = GetSetting(App.EXEName, "Cotelp", "txttelp", "")
    8.        
    9.        con_cashreg.Open STring2
    10.        msql = "select * From invoicedetail "
    11.        'If rs.State = adStateOpen Then rs.Close
    12.        Rs2.CursorLocation = adUseClient  'For Sortinf
    13.        
    14.        con_cashreg.Execute (msql)
    15.        Rs2.Open msql, con_cashreg, adOpenKeyset, adLockPessimistic, adCmdText
    16.        
    17.        MSHFlexGrid1.Redraw = False
    18.  
    19.        MSHFlexGrid1.Cols = 10
    20.        MSHFlexGrid1.ColWidth(0) = 0
    21.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 1
    22.        MSHFlexGrid1.Text = "Invoice Id"
    23.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 2:
    24.        MSHFlexGrid1.Text = "Prod Id"
    25.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 3:
    26.        MSHFlexGrid1.Text = "Prod Name"
    27.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 4:
    28.        MSHFlexGrid1.Text = "Unit"
    29.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 5:
    30.        MSHFlexGrid1.Text = "Sale Price"
    31.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 6:
    32.        MSHFlexGrid1.Text = "Quantity"
    33.        MSHFlexGrid1.Row = 0:       MSHFlexGrid1.Col = 7:
    34.        MSHFlexGrid1.Text = "Amount"
    35.        
    36.        MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
    37.        
    38.         With Rs2
    39.             While Not Rs2.EOF
    40.                 MSHFlexGrid1.Col = 1
    41.                 MSHFlexGrid1.Text = Rs2!invoiceid
    42.                 MSHFlexGrid1.Col = 2
    43.                 MSHFlexGrid1.Text = Rs2!productid
    44.                 MSHFlexGrid1.Col = 3
    45.                 MSHFlexGrid1.Text = Rs2!ProductName
    46.                 MSHFlexGrid1.Col = 4
    47.                 MSHFlexGrid1.Text = Rs2!unit
    48.                 MSHFlexGrid1.Col = 5
    49.                 MSHFlexGrid1.Text = Rs2!saleprice
    50.                 MSHFlexGrid1.Col = 6
    51.                 MSHFlexGrid1.Text = Rs2!quantity
    52.                 MSHFlexGrid1.Col = 7
    53.                 MSHFlexGrid1.Text = Rs2!amount
    54.                
    55.                 MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
    56.                 MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
    57.                 .MoveNext
    58.             Wend
    59.             Rs2.Close
    60.         End With
    61.  
    62.        MSHFlexGrid1.Redraw = True
    63.  
    64. End Sub

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: mshflexgrid refresh help

    Quote Originally Posted by ksuwanto8ksd
    but nothing happen to the grid
    Are you sure this
    Code:
    msql = "delete * from invoicedetail"
    is empting the table?
    May be TRUNCATE TABLE is better?

  5. #5

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: mshflexgrid refresh help

    hi ember
    sure, I am very sure invoicedetail is deleted and empty after delete
    how to truncate a table? can you advise pls thanks

    happy new year

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: mshflexgrid refresh help

    From Books Online (SQLServer):
    Code:
    TRUNCATE TABLE
    Removes all rows from a table without logging the individual row deletes. 
    
    Syntax
    TRUNCATE TABLE name

  7. #7

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: mshflexgrid refresh help

    I'm using access 2k is truncate support it? What is the different between truncate table and using "delete * from table" ? and What condition is required to use truncate table?

    really appreciate, thanks.

  8. #8
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: mshflexgrid refresh help

    Access (makes me uncertain) but:
    Code:
    Delete Method (ADO Recordset)
    Deletes the current record or a group of records.
    
    Syntax
    recordset.Delete AffectRecords
    
    Parameters
    AffectRecords 
    An AffectEnum value that determines how many records the Delete method will affect. The default value is adAffectCurrent. 
    Note   adAffectAll and adAffectAllChapters are not valid arguments to Delete.

  9. #9

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: mshflexgrid refresh help

    Is the truncate work fine in access 2k? if yes
    Can you show an example code using truncate pls

    really appreciate, thanks ember

  10. #10

  11. #11
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: mshflexgrid refresh help

    If you are deleting all in that Table then you don't need to Refresh, just use
    VB Code:
    1. MSHFlexGrid1.Rows = 1
    But if you want to execute a different commandstring and you really need to Refresh then you need to execute the code in your Form_Load event again, so it would be much better if you remove that code from there and add it to another Sub and call that sub in Form_Load and whenever you need to Refresh the Grid after a change.

    Also, inside that new Sub that Refreshes your Grid, add MSHFlexGrid1.Rows = 1 on top.

  12. #12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width