【发布时间】:2013-04-03 09:12:43
【问题描述】:
在 MS-Access 中,如何将 SELECT 语句检索到的行存储在一个数组中,并在一个消息框中显示多行:
Dim rSEL, rSUM, rDes As DAO.Recordset
Dim vItem_id, vQnty, vSum As Integer
Dim vDes As String
If Not IsNull(itemId) And Not IsNull(qnty_in) Then
If qnty_in <= 0 Or qnty_in > balance Or IsNull(balance) Then
Cancel = True
End If
Set rSEL = CurrentDb.OpenRecordset("SELECT item_id,item_qnty
FROM basketQnty_tbl WHERE basket_id=" & basketId)
'Check to see if the recordset actually contains rows
If Not (rSEL.EOF And rSEL.BOF) Then
rSEL.MoveFirst
Do Until rSEL.EOF
'Save itemId into a variable
vItem_id = rSEL!item_id
vQnty = (rSEL!item_qnty) * qnty_in
Set rSUM = CurrentDb.OpenRecordset("SELECT sum(qnty_in*qnty_type)
as QN FROM sales_tbl WHERE itemid=" & vItem_id)
Set rDes = CurrentDb.OpenRecordset("SELECT itemDesc
FROM items_main WHERE itemId=" & vItem_id)
vSum = rSUM!QN
vDes = rDes!itemDesc
'Move to the next record. Don't ever forget to do this.
If vQnty > vSum Then
MsgBox "you have only (" & vSum & " ) of Item (" & vDes & " ) in the stock"
Cancel = True
End If
rSEL.MoveNext
Loop
End If
rSEL.Close
End If
【问题讨论】:
-
为什么要将返回的记录存储在数组中?
-
我想显示一个消息框,说你没有足够数量的列出的项目
-
您不需要数组来从记录集中取出数据并显示在消息框中。
-
先生。 @MarkBertenshaw我知道我可以为每条记录显示masgebox ...当我单击确定时它显示...另一个消息框但我想显示一个消息框,它在一个消息框中显示所有选定的记录
-
我在阅读问题一段时间后猜到了。一般来说,永远不要将消息框放入循环中,除非您要立即退出循环。无论如何,我已经回答了下面的问题。
标签: arrays vba ms-access vb6 ms-access-2007