|
5#
楼主 |
发表于 2008-1-21 12:02:09
|
只看该作者
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
改成以上的,就可以执行,我就是想不通,为什么用rs.delete删除不了当前记录,而用 docmd.runsql 可以
就是加了rs.update也没有用,点击后还是没有任何反映
同样用版主的CurrentDb.Execute ("delete from 物品资料表 where 产品代码='" & Me![Frm_物品资料输入子窗体]![产品代码] & "'")也能执行
版主能否说明一下我前面的错误在哪里?
[ 本帖最后由 su_xx 于 2008-1-21 12:06 编辑 ] |
|