主题:VB ACCESS 删除问题
麻烦各位大侠,小弟这个代码运行后只能删除显示窗口记录,数据库中记录还在,是什么原因,请各位大侠指点。代码如下:
'程序入口
Sub OpenConn()
Dim connectionstring As String
DataPath = App.Path + "\company.mdb"
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataPath + ";Persist Security Info=False" + ";Jet OLEDB:Database Password=tan1987320"
conn.Open connectionstring
'cnt = 0
删除
Private Sub cmdDel_Click()
Dim sq As String
On Error GoTo aaaa
Dim i As Long, j As Long
j = 0
For i = 1 To List1.ListItems.Count
If List1.ListItems(i).Selected = True Then j = j + 1
Next
If j = 0 Then
MsgBox "没有选中任何客户。", vbInformation
Exit Sub
End If
If MsgBox("注意:此操作会同时删除客户记录。" & vbCrLf & vbCrLf & "确定删除选中的 " & j & " 个客户吗?", vbInformation + vbOKCancel + vbDefaultButton2) = vbCancel Then Exit Sub
For i = List1.ListItems.Count To 1 Step -1
If List1.ListItems(i).Selected = True Then
Call OpenConn
sq = "Delete* From [客户管理] Where 客户编号='" & List1.ListItems(i).SubItems(1) & "'"
conn.Execute sq
conn.Close
Set conn = Nothing
List1.ListItems.Remove i
End If
Next
Exit Sub
aaaa:
MsgBox Err.Description, vbCritical
'程序入口
Sub OpenConn()
Dim connectionstring As String
DataPath = App.Path + "\company.mdb"
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataPath + ";Persist Security Info=False" + ";Jet OLEDB:Database Password=tan1987320"
conn.Open connectionstring
'cnt = 0
删除
Private Sub cmdDel_Click()
Dim sq As String
On Error GoTo aaaa
Dim i As Long, j As Long
j = 0
For i = 1 To List1.ListItems.Count
If List1.ListItems(i).Selected = True Then j = j + 1
Next
If j = 0 Then
MsgBox "没有选中任何客户。", vbInformation
Exit Sub
End If
If MsgBox("注意:此操作会同时删除客户记录。" & vbCrLf & vbCrLf & "确定删除选中的 " & j & " 个客户吗?", vbInformation + vbOKCancel + vbDefaultButton2) = vbCancel Then Exit Sub
For i = List1.ListItems.Count To 1 Step -1
If List1.ListItems(i).Selected = True Then
Call OpenConn
sq = "Delete* From [客户管理] Where 客户编号='" & List1.ListItems(i).SubItems(1) & "'"
conn.Execute sq
conn.Close
Set conn = Nothing
List1.ListItems.Remove i
End If
Next
Exit Sub
aaaa:
MsgBox Err.Description, vbCritical