--------------------------------------------
Option Compare Database
Private Sub cmdAdd_Click()
'添加记录
On Error GoTo Err_cmdAdd_Click
'DoCmd.GoToRecord , , acFirst
DoCmd.GoToRecord , , acNewRec
cmdMod.Enabled = True
cmdMod.SetFocus
cmdAdd.Enabled = False
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
Private Sub cmdMod_Click()
'修改库存
Dim curdb As Database
Dim curRS As Recordset
Dim deviceCnt As Integer
Set curdb = CurrentDb
Set curRS = curdb.OpenRecordset("select * from 库存表 where 产品编号 ='" & 产品编号.Value & "'")
If Not curRS.EOF Then
deviceCnt = curRS.Fields("库存量")
deviceCnt = deviceCnt + CInt(进库数量.Value)
curdb.Execute "update 库存表 set 库存量=" & deviceCnt & "where 产品编号='" & 产品编号.Value & "'"
Else
With curRS
.AddNew
.Fields("产品编号") = 产品编号.Value
.Fields("库存量") = CInt(进库数量.Value)
.Fields("存放地点") = "广州"
.Update
End With
End If
cmdAdd.Enabled = True
cmdAdd.SetFocus
cmdMod.Enabled = False
End Sub
------------------------------ |