我用两个时间插件:DTPicker1 DTPicker2 和一个按钮Command1 。选择其中的一段时间删除,在按钮中执行下面代码但是不行 请帮我看看谢谢!如果能帮我加上一个进度条那更好了
Private Sub Command1_Click()
If MsgBox("您真的要删除吗?", vbYesNo + 32, "信息删除") = vbYes Then ' 用户按下"是"
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hao"
strsql = "delete xx where 发送时间 >= " & "'" & DTPicker1.Value & "'and 发送时间 <= " & "'" & DTPicker2.Value & "'ORDER BY 发送时间"
Adodc1.RecordSource = strsql
Adodc1.Refresh ' 完成某操作
End If
End Sub
Private Sub Command1_Click()
If MsgBox("您真的要删除吗?", vbYesNo + 32, "信息删除") = vbYes Then ' 用户按下"是"
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hao"
strsql = "delete xx where 发送时间 >= " & "'" & DTPicker1.Value & "'and 发送时间 <= " & "'" & DTPicker2.Value & "'ORDER BY 发送时间"
Adodc1.RecordSource = strsql
Adodc1.Refresh ' 完成某操作
End If
End Sub
Dim WithEvents cn As ADODB.Connection那么在下面的事件中你可以知道执行已经完成,是否出错,删除了多少条记录:
Private Sub cn_ExecuteComplete(ByVal RecordsAffected As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pCommand As ADODB.Command, ByVal pRecordset As ADODB.Recordset, ByVal pConnection As ADODB.Connection)End Sub如果你一定要进度条方式同步删除,可以:
Dim cn As ADODB.Connection, rs As ADODB.RecordsetSet cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cn.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hao"
Set rs = New ADODB.Recordset
rs.Open "select * from tablename where 发送时间 >= '" & Format(DTPicker1.Value, "yyyy-mm-dd") & "' and 发送时间 <= '" & Format(DTPicker2.Value, "yyyy-mm-dd") & "'", cnStatusBar1.Max = rs.RecordCount
StatusBar1.Value = 0
rs.MoveLast
Do Until rs.EOF
rs.Delete
rs.MoveNext
StatusBar1.Value = StatusBar1.Value + 1
StatusBar1.Refresh
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing