显示多个验证信息给用户 [英] Display multiple validation messages to the user
问题描述
在MS-Access中,我怎么能存储从我的SELECT语句中的数组返回的行,并显示多行一个消息框:
暗淡RSEL,RSUM,快速发展经济体作为DAO.Recordset
朦胧vItem_id,vQnty,VSUM作为整数
昏暗的vDes作为字符串
如果不ISNULL(的itemId),而不是ISNULL(qnty_in)然后
如果qnty_in< = 0或qnty_in>天平或ISNULL(平衡)然后
取消= TRUE
结束如果
设置RSEL = CurrentDb.OpenRecordset(SELECT ITEM_ID,item_qnty
从basketQnty_tbl WHERE basket_id =&放大器; basketId)
请检查记录实际上包含行
如果不是(rSEL.EOF而rSEL.BOF)然后
rSEL.MoveFirst
做直到rSEL.EOF
保存ITEMID到一个变量
vItem_id = RSEL!ITEM_ID
vQnty =(RSEL!item_qnty)* qnty_in
设置RSUM = CurrentDb.OpenRecordset(SELECT SUM(qnty_in * qnty_type)
作为QN从sales_tbl中WHERE itemid的=&放大器; vItem_id)
设置快速发展经济体= CurrentDb.OpenRecordset(选择itemDesc
从items_main WHERE的itemId =&放大器; vItem_id)
VSUM = RSUM!QN
vDes = RDE国家!itemDesc
移动到下一个记录。永远不要忘记这样做。
如果vQnty> VSUM然后
MSGBOX你只有(&放大器; VSUM&安培;)项目(&放大器; vDes&安培;)的股票
取消= TRUE
结束如果
rSEL.MoveNext
循环
结束如果
rSEL.Close
结束如果
我不会用一个消息框对于这一点,因为你可能有数百行,而且他们也不会都适合。相反,我会用一个列表框创建自定义表单,而当你得到错误,请执行下列操作:
如果vQnty> VSUM然后
< ErrorForm><列表框> .AddItem(你只(与& VSUM&安培;)项目(&放大器; vDes&安培;)股票)
取消= TRUE
结束如果
如果在循环结束时,取消= TRUE,显示ErrorForm。
另一件事 - 你也许可以创建一个做这一切一气呵成的查询。你需要加入三个表,并添加vQnty> VSUM条件。这将是pretty的整洁,因为你可以使用查询作为列表框的源 - 无需code
In MS-Access, how can I store the rows retrieved from my SELECT statement in an array, and show many rows in one messagebox:
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
I would not use a Message Box for this, since you could potentially have hundreds of rows, and they wouldn't all fit. Instead, I would create a custom form with a ListBox, and whenever you get the error, do the following:
If vQnty > vSum Then
<ErrorForm>.<ListBox>.AddItem("You have only (" & vSum & " ) of Item (" & vDes & " ) in the stock")
Cancel = True
End If
If at the end of the loop, Cancel = True, display ErrorForm.
Another thing - you may be able to create a query which does all this in one go. You need to join the three tables, and add the vQnty > vSum condition. This would be pretty neat, because you could use the query as the source of the ListBox - no code required.
这篇关于显示多个验证信息给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!