Private Sub Command15_Click()
Dim sql As String
Dim rst As ADODB.Recordset
Dim number As Integer
If IsNull(Me![仓库编号]) Then
MsgBox "请选择仓库"
DoCmd.GoToControl "仓库编号"
ElseIf IsNull(Me![商品编号]) Then
MsgBox "请选择商品编号"
DoCmd.GoToControl "商品编号"
Else
sql = "select *from 商品表 where [仓库编号]= '" & Me![仓库编号] & "'"
sql = sql & "and [商品编号]=" & Me![商品编号]
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open sql
If Not (rst.EOF) Then
number = rst!当前库存数量
rst.Close
Set rst = Nothing
sql = "当前库存数量为:" & number
MsgBox sql
Exit Sub
Else
rst.Close
Set rst = Nothing
MsgBox "当前仓库中没有该商品库存"
Exit Sub
End If
End If
End Sub