Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何检查一张桌子上的数量是多还是少?_Vba_Ms Access - Fatal编程技术网

Vba 如何检查一张桌子上的数量是多还是少?

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

我需要检查我是否有足够数量的特定产品。我如何使它检查的数量是文本框(txtIdProd)中产品的数量

这是我的代码:

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不应该是