如何用VBA代码更新access中的表记录,我的其中一段代码出现了问题(更新操作 .AddNew)

Private Sub Command14_Click()
Dim rst As ADODB.Recordset
Dim number As Integer
Dim sql As String

If IsNull(Me![仓库编号]) Then
    MsgBox "请选择仓库"
    DoCmd.GoToControl "仓库编号"
ElseIf IsNull(Me![商品编号]) Then
    MsgBox "请选择商品编号"
    DoCmd.GoToControl "商品编号"
ElseIf IsNull(Me![数量]) Then
    MsgBox "请选择数量"
    DoCmd.GoToControl "数量"
ElseIf IsNull(Me![经手员工编号]) Then
    MsgBox "请选择经手员工编号"
    DoCmd.GoToControl "经手员工编号"
ElseIf IsNull(Me![出库日期]) Then
    MsgBox "请选择出库日期"
    DoCmd.GoToControl "出库日期"
ElseIf IsNull(Me![订单编号]) Then
    MsgBox "请选择订单编号"
    DoCmd.GoToControl "订单编号"
ElseIf IsNull(Me![送货方式]) Then
    MsgBox "请选择送货方式"
    DoCmd.GoToControl "送货方式"
Else
    sql = "select * from 商品表 where 商品编号='" & Me.商品编号 & "'"
    Set rst = New ADODB.Recordset
    rst.ActiveConnection = CurrentProject.Connection
    rst.CursorType = adOpenDynamic
    rst.LockType = adLockOptimistic
    rst.Open sql
    If Not (rst.EOF) Then
        '修改库存信息
        sql = "select *from 商品表 where 仓库编号='" & Me.仓库编号 & "'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!数量
            number = number - Me![数量]
            rst!数量 = number
            'rst.Close
            'Set rst = Nothing
            sql = "当前库存数量为:" & number
            MsgBox sql
            Exit Sub
        Else
            rst.Close
            Set rst = Nothing
            MsgBox "没有该商品的库存信息,不能出库"
            Exit Sub
        End If
    '添加出库记录
        sql = "select * from 出库记录表"
        rst.Close
        Set rst = Nothing
        Set rst = New ADODB.Recordset
        rst.ActiveConnection = CurrentProject.Connection
        rst.CursorType = adOpenKeyset
        rst.LockType = adLockOptimistic
        rst.Open sql

With rst

.AddNew

.Update = Me![仓库编号]

!商品编号 = Me![商品编号]

!数量 = Me![数量]

!经手员工编号 = Me![经手员工编号]

!出库日期 = Me![出库日期]

!订单编号 = Me![订单编号]

!送货方式 = Me![送货方式]

End With

rst.Close

Set rst = Nothing

    Else
        rst.Close
        Set rst = Nothing
        MsgBox "系统中没有该商品的信息,请先添加商品详细信息"
        Exit Sub
        Me.Visible = False
    End If
End If

End Sub

加粗的代码不能正常执行
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐