[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:
Private Sub cmdDelete_Click()
Dim msql As String
Dim Delete As String
con_cashreg.BeginTrans
Delete = MsgBox("Are you really to delete???", vbYesNo + vbCritical, "Delete")
If Delete = vbYes Then
msql = "delete * from invoicedetail"
con_cashreg.Execute (msql)
con_cashreg.CommitTrans
Else
con_cashreg.CommitTrans
End If
End Sub
I really appreciate if anyone can help me
thanks and happy new year 2007
Re: mshflexgrid refresh help
I try this so far :
but nothing happen to the grid
thanks
Re: mshflexgrid refresh help
additional information,
in form load I populate mshflexgrid like this:
VB Code:
Private Sub Form_Load()
Dim msql As String
Me.WindowState = 2
Label1.Caption = GetSetting(App.EXEName, "CoName", "txtco", "")
Label2.Caption = GetSetting(App.EXEName, "CoAdd", "txtAdd", "")
Label3.Caption = GetSetting(App.EXEName, "Cotelp", "txttelp", "")
con_cashreg.Open STring2
msql = "select * From invoicedetail "
'If rs.State = adStateOpen Then rs.Close
Rs2.CursorLocation = adUseClient 'For Sortinf
con_cashreg.Execute (msql)
Rs2.Open msql, con_cashreg, adOpenKeyset, adLockPessimistic, adCmdText
MSHFlexGrid1.Redraw = False
MSHFlexGrid1.Cols = 10
MSHFlexGrid1.ColWidth(0) = 0
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 1
MSHFlexGrid1.Text = "Invoice Id"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 2:
MSHFlexGrid1.Text = "Prod Id"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 3:
MSHFlexGrid1.Text = "Prod Name"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 4:
MSHFlexGrid1.Text = "Unit"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 5:
MSHFlexGrid1.Text = "Sale Price"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 6:
MSHFlexGrid1.Text = "Quantity"
MSHFlexGrid1.Row = 0: MSHFlexGrid1.Col = 7:
MSHFlexGrid1.Text = "Amount"
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
With Rs2
While Not Rs2.EOF
MSHFlexGrid1.Col = 1
MSHFlexGrid1.Text = Rs2!invoiceid
MSHFlexGrid1.Col = 2
MSHFlexGrid1.Text = Rs2!productid
MSHFlexGrid1.Col = 3
MSHFlexGrid1.Text = Rs2!ProductName
MSHFlexGrid1.Col = 4
MSHFlexGrid1.Text = Rs2!unit
MSHFlexGrid1.Col = 5
MSHFlexGrid1.Text = Rs2!saleprice
MSHFlexGrid1.Col = 6
MSHFlexGrid1.Text = Rs2!quantity
MSHFlexGrid1.Col = 7
MSHFlexGrid1.Text = Rs2!amount
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
.MoveNext
Wend
Rs2.Close
End With
MSHFlexGrid1.Redraw = True
End Sub
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?
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
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
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.
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.
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
Re: mshflexgrid refresh help
How to refresh a mshflexgrid anyone help pls?
Re: mshflexgrid refresh help
If you are deleting all in that Table then you don't need to Refresh, just use
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.
Re: mshflexgrid refresh help
Yes working
Thanks Jcis
Appreciate