最近碰到这样一个问题 我用的是FlexGrid 控件,但是当我打入代码后,运行时确发现对表实现查询无论是按取消和确定都会显示出表的内容,这是怎么回事啊? 是不是MSGBOX显示的时候对于那个取消我没有做代码的解释啊? 我的代码是:: Private Sub Command1_Click() Dim query_text As String '存放用户查找要求 Dim i As Integer Dim Last_Pos As Variant Me.MSFlexGrid1.Rows = 2 Me.MSFlexGrid1.Cols = 5 Me.MSFlexGrid1.Clear Me.MSFlexGrid1.TextMatrix(0, 1) = "物品名" Me.MSFlexGrid1.TextMatrix(0, 2) = "物品描述" Me.MSFlexGrid1.TextMatrix(0, 3) = "库存" Me.MSFlexGrid1.TextMatrix(0, 4) = "价格" Me.MSFlexGrid1.ColWidth(0) = "400" Me.MSFlexGrid1.ColWidth(1) = "1000" Me.MSFlexGrid1.ColWidth(2) = "1000" Me.MSFlexGrid1.ColWidth(3) = "1000" Me.MSFlexGrid1.ColWidth(4) = "800" Last_Pos = Me.Data3.Recordset.Bookmark '记住当前记录 query_text = InputBox("请查询物品(空白表示全部)", "查询") Me.Data3.Recordset.MoveFirst Me.Data3.Recordset.FindFirst "[物品名]like '" & query_text & "*'" If Me.Data3.Recordset.NoMatch Then Me.Data3.Recordset.Bookmark = Last_Pos '没找到,恢复当前记录。 Else '找到第1个
i = 1 Me.MSFlexGrid1.TextMatrix(1, 0) = i Me.MSFlexGrid1.TextMatrix(1, 1) = Me.Data3.Recordset.Fields(0) Me.MSFlexGrid1.TextMatrix(1, 2) = Me.Data3.Recordset.Fields(1) Me.MSFlexGrid1.TextMatrix(1, 3) = Me.Data3.Recordset.Fields(2) Me.MSFlexGrid1.TextMatrix(1, 4) = Me.Data3.Recordset.Fields(3) Me.Data3.Recordset.FindNext "[物品名]like '" & query_text & "*'" '找下1个 Do While (Not Me.Data3.Recordset.NoMatch) '找到 i = i + 1 Me.MSFlexGrid1.AddItem (i) Me.MSFlexGrid1.TextMatrix(i, 1) = Me.Data3.Recordset.Fields(0) Me.MSFlexGrid1.TextMatrix(i, 2) = Me.Data3.Recordset.Fields(1) Me.MSFlexGrid1.TextMatrix(i, 3) = Me.Data3.Recordset.Fields(2) Me.MSFlexGrid1.TextMatrix(i, 4) = Me.Data3.Recordset.Fields(3) Me.Data3.Recordset.FindNext "[物品名]like '" & query_text & "*'" '找下1个 Loop End If End Sub