奇特的列表框。查看可视错误

时间:2015-05-12 16:51:11

标签: vba ms-access listbox access-vba

我有一个列表框,根据组合框中的值过滤AfterUpdate事件。一切正常,但有时它没有正确显示所有记录。

但是,如果我只是点击列表框中的一行,它就会自行纠正。

此外,它在显示错误时显示数据的方式非常特殊 - 它完全显示了最后一列,但其余数据都搞砸了。

知道如何解决这个问题吗?我在Me.listBoxName.Requery中有一个简单的cboObjedn_AfterEvent()作为最后一个通道,在这样做之前从未遇到过问题。

我附上了2张图片,显示了一个例子(通常有10行以上,而不是2行)。Before clicking on the row of data

After clicking on the row of data

编辑: AfterUpdate子代码如下:

Private Sub cboOrder_ID_AfterUpdate()

    Dim rst As DAO.Recordset

    Set rst = CurrentDb.OpenRecordset(mSQL(Me))
    Set Me.lst1Model_Operation.Recordset = rst
    Me.lst1Model_Operation.Requery

End Sub

Public Property Get mSQL(object As Object) As String
mySQL = "SELECT MO.Model_Operation_ID, MO.Model_ID, MO.Operation_Value_ID, OV.Operation_Name_ID, OL.Operation_Name AS Operácia, OM.Quantity AS [Poèet párov], " & "Format([OV].[Value], " & """0.0000 €""" & ")" & "AS Sadzba, OM.Order_ID, OM.Order_Name, ML.Model_Name" _
        & " FROM tbl2ModelsList AS ML INNER JOIN (tbl3OperationsList AS OL INNER JOIN (tbl2Operation_Value AS OV INNER JOIN (tbl1Model_Operation AS MO INNER JOIN tbl1Order_Model AS OM ON MO.Model_ID = OM.Model_ID) ON OV.Operation_Value_ID = MO.Operation_Value_ID) ON OL.Operation_ID = OV.Operation_Name_ID) ON ML.Model_ID = OM.Model_ID" _
        & " WHERE (((OM.Order_ID)=" & object.cboOrder_ID & "))"
End Property

1 个答案:

答案 0 :(得分:2)

将查询语句分配给列表框的 RowSource 属性:

Me.lst1Model_Operation.RowSource = mSQL(Me)

更改 RowSource 会更新列表框内容以响应更新的SELECT声明,因此您无需再次在代码中调用Requery