问题描述
Private Sub btn_delete_Click()
On Error GoTo Err_btn_delete_Click
声明变量
'declare variables
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
表格中插入的所有数据
'check the data inserted
If IsNull(Me.txt_name) Or Me.txt_name = "" Then
MsgBox "name not entered",vbCritical,"Test ADO"
Exit Sub
End If
删除数据
'delete data
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.source = "TableClass" 'table name
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.CursorLocation = adUseServer
.Open
do while Not rs.EOF
If rs!Name = txt_name.Value Then
rs.Delete
End If
rs.MoveNext
Loop
Set rs = nothing
Set cn = nothing
End With
全部重置并退出
'reset contents
txt_name.Value = ""
'exit operation
MsgBox "Operation completed",vbExclamation,"Test ADO"
Exit_btn_delete_Click:
Exit Sub
Err_btn_delete_Click:
MsgBox Err.Description
Resume Exit_btn_delete_Click
End Sub
我已多次尝试此代码,但它不起作用,但我不知道问题出在哪里。 在按钮的点击事件过程中,我使用了代码构建器
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)