Private Sub Cmd_删除产品_Click()
On Error GoTo Err_Cmd_删除产品
Dim i As Integer
Dim Stemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Stemp = "Select * From 物品资料表"
Rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockBatchOptimistic
If Rs.RecordCount < 1 Then
Exit Sub
End If
Rs.MoveFirst
For i = 1 To Rs.RecordCount
If Rs("产品代码") = Me![Frm_物品资料输入子窗体]![产品代码] Then
Rs.Delete adAffectCurrent
Exit For
Else
Rs.MoveNext
End If
Next i
MsgBox "产品代码:" & Me![产品代码] & "的资料已经删除完成!", vbOKOnly, "删除完成"
Me![Frm_物品资料输入子窗体].Requery
Set Rs = Nothing
Exit_Cmd_删除产品:
Set Rs = Nothing
Exit Sub
Err_Cmd_删除产品:
MsgBox Err.Description
Resume Exit_Cmd_删除产品
End Sub作者: rjacky 时间: 2008-1-21 11:36
应该是漏了个Rs.update吧
CurrentDb.Execute ("delete from 物品表名字 where 产品代码='" & me!子窗体名字!产品代码 & "'")作者: su_xx 时间: 2008-1-21 12:02
Stemp = "DELETE 物品资料表.产品代码 FROM 物品资料表 WHERE (((物品资料表.产品代码)='" & Me.产品代码 & "'))"
DoCmd.RunSQL Stemp
Private Sub Cmd_删除产品_Click()
On Error GoTo Err_Cmd_删除产品
Dim i As Integer
Dim Stemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
Stemp = "Select * From 物品资料表"
Rs.Open Stemp, CurrentProject.Connection, adOpenKeyset, adLockBatchOptimistic
If Rs.RecordCount < 1 Then
Exit Sub
End If
Rs.MoveFirst
For i = 1 To Rs.RecordCount
If Rs("产品代码") = Me![Frm_物品资料输入子窗体]![产品代码] Then
' Rs.Delete adAffectCurrent
Stemp = "DELETE 物品资料表.产品代码 FROM 物品资料表 WHERE (((物品资料表.产品代码)='" & Me.产品代码 & "'))"
DoCmd.RunSQL Stemp
Exit For
Else
Rs.MoveNext
End If
Next i
MsgBox "产品代码:" & Me![产品代码] & "的资料已经删除完成!", vbOKOnly, "删除完成"
Me![Frm_物品资料输入子窗体].Requery
Set Rs = Nothing
Exit_Cmd_删除产品:
Set Rs = Nothing
Exit Sub
Err_Cmd_删除产品:
MsgBox Err.Description
Resume Exit_Cmd_删除产品
End Sub