我继承了一些Access VBA代码,并且表单上有控件(例如下面提到的名为lstOrderID
的列表框),它们没有设置RowSource属性(空字符串)。我查看代码并在各个地方查找这样的语句:
Forms!frm_Customer.lstOrderID = rstCust!OrderID ' set from a record set
Forms!frm_Customer.lstOrderID.Requery
Me.lstOrderID = Me.lstOrderID.ItemData(0) ' set to first item in self
但代码中没有任何地方正在设置lstOrderID.RowSource。
如何在没有RowSource的列表框上调用Requery
?
如何将列表框设置为记录集中的单个值(rstCust!OrderID
),除非这是值列表(尽管调试器在lstOrderID.Value
中显示整数)?
这是更多代码:
Dim rstCust As Recordset
Set db = CurrentDb
Set rstCust = db.OpenRecordset("SELECT * FROM Orders WHERE CustID=" & ID & _
"AND Datetaken =Date() " & _
"AND VendorID='" & Forms!frm_Customer.cboVendorID & "'")
Forms!frm_Customer.lstOrderID = rstCust!OrderID
rstCust.Close
db.Close
另一部分:
Dim rstCust As Recordset
Dim blStatus As Boolean
Dim strSql As String
Set db = CurrentDb
strSql = "SELECT Orders.OrderID " & _
"FROM Orders " & _
"WHERE (((Orders.DateTaken)=#" & Date & "#) " & _
"AND ((Orders.VendorID)='" & Forms!frm_Customer.cboVendorID & "') " & _
"AND ((Orders.CustID)=" & ID & "));"
Set rstCust = db.OpenRecordset(strSql)
Forms!frm_Customer.lstOrderID = rstCust!OrderID
Forms!frm_Customer.lstOrderID.Requery
Forms!frm_Customer.lstOrderID = rstCust!OrderID
rstCust.Close
db.Close
还有:
Me.lstOrderID.Requery
Me.lstOrderID = Me.lstOrderID.ItemData(0)