Vba 如何检查一张桌子上的数量是多还是少?
我需要检查我是否有足够数量的特定产品。我如何使它检查的数量是文本框(txtIdProd)中产品的数量 这是我的代码:Vba 如何检查一张桌子上的数量是多还是少?,vba,ms-access,Vba,Ms Access,我需要检查我是否有足够数量的特定产品。我如何使它检查的数量是文本框(txtIdProd)中产品的数量 这是我的代码: Private Sub Cantidad_LostFocus() Set myDatabase = CurrentDb() Set myRs = myDatabase.OpenRecordset("TblProductos", dbOpenDynaset) Dim cant As Integer cant = txtCantidad myRs.FindFirst "IDProdu
Private Sub Cantidad_LostFocus()
Set myDatabase = CurrentDb()
Set myRs = myDatabase.OpenRecordset("TblProductos", dbOpenDynaset)
Dim cant As Integer
cant = txtCantidad
myRs.FindFirst "IDProducto=" & Me.txtIdProd
If myRs.NoMatch = False Then
If cant > myRs("CantidadDisponible") Then
Me.Label27.Visible = True
End If
End If
Exit Sub
Me.Label27.Visible = False
End Sub
FindFirst代码应该完全满足您的要求。但是,过滤记录集可能更有效
Private Sub Cantidad_LostFocus()
Dim cant As Integer
If Not IsNull(Me.txtIDProd) Then
Set myDatabase = CurrentDb()
Set myRs = myDatabase.OpenRecordset("SELECT CantidadDisponible FROM TblProductos WHERE IDProducto=" & Me.txtIdProd, dbOpenDynaset)
cant = rs!CantidadDisponible
End If
Me.Label27.Visible = Me.txtCantidad <= cant
End Sub
Private Sub Cantidad_LostFocus()
将铁路超高设置为整数
如果不是IsNull(Me.txtIDProd),则
设置myDatabase=CurrentDb()
Set myRs=myDatabase.OpenRecordset(“从TblProductos中选择cantidaddisponsible,其中IDProducto=“&Me.txtIdProd,dbOpenDynaset”)
不能=卢比!康蒂达责任
如果结束
Me.Label27.Visible=Me.txtCantidad谢谢,原来我只是在一个旧的sub中编辑,因为我更改了名称,忘记了。看看你的工作原理。为什么不使用组合框而不是文本框?txtCantidad不应该是