i just want to ask how to clear the data from flexgrid.
im using textbox to search data from flexgrid and its almost perfect but when the data i type on textbox is not in the flexgrid the flexgrid still have all the data from the database.i want to clear the data from flexgrid once the data that i type on textbox is not in the flexgrid...can someone pls help me tnx..
here is my code::
Private Sub Text3_Change()
If Me.Text3.Text = "" Then
clear
ShowTable
Exit Sub
End If
Dim rs As New ADODB.Recordset
On Error GoTo err:
rs.Open "SELECT * FROM pharmainventory where medicine_name like '" & Me.Text3.Text & "%'", con, adOpenKeyset, adLockOptimistic
rs.MoveFirst
With MSFlexGrid1
'column width
.ColWidth(0) = 300
.ColWidth(1) = 0
.ColWidth(2) = 3000
.ColWidth(3) = 1500
.ColWidth(4) = 3000
.ColWidth(5) = 1200
.ColWidth(6) = 1800
'Header
.TextMatrix(0, 2) = "Medicine Name"
.TextMatrix(0, 3) = "Mg / Ml"
.TextMatrix(0, 4) = "Make"
.TextMatrix(0, 5) = "Quantity"
.TextMatrix(0, 6) = "Price / Quantity"
'text alignment
.ColAlignment(2) = flexAlignLeftCenter
.ColAlignment(3) = flexAlignLeftCenter
.ColAlignment(4) = flexAlignLeftCenter
.ColAlignment(5) = flexAlignLeftCenter
.ColAlignment(6) = flexAlignLeftCenter
' the data
While Not rs.EOF
.TextMatrix(.Rows - 1, 1) = rs.Fields(0)
.TextMatrix(.Rows - 1, 2) = rs.Fields(1)
.TextMatrix(.Rows - 1, 3) = rs.Fields(2)
.TextMatrix(.Rows - 1, 4) = rs.Fields(3)
.TextMatrix(.Rows - 1, 5) = rs.Fields(4)
.TextMatrix(.Rows - 1, 6) = rs.Fields(5)
rs.MoveNext
.Rows = .Rows + 1
Wend
.Rows = .Rows - 1
End With
i use the code below on a datagrid and its working fine...but on flexgrid its a no no...?????????????
With rspharmainventory
.MoveFirst
While .EOF = False
If .Fields(1) = Me.Text3.Text Then
Me.txtmedicinename.Text = .Fields(1)
Me.txtmg.Text = .Fields(2)
Me.txtmake.Text = .Fields(3)
exit sub
else
clear
MSFlexGrid1.clear ' do i need to use this????
end if
.MoveNext
Wend
End With
rs.Close
err:
End Sub
- Add new comment
- 68 views