示例下载:点击下载此附件
代码如下:
'************ Code Start ***********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
Private Declare Function apiGetAsyncKeyState Lib "user32" _
Alias "GetAsyncKeyState" _
(ByVal vKey As Long) _
As Integer
Private Const VK_ESCAPE = &H1B
Function fBreakInCode()
'需要引用DAO3.6,否则编译出错
Dim boolEsc As Boolean
Dim rs As DAO.Recordset
Dim i As Double
Set rs = CurrentDb.OpenRecordset("SomeTable", dbOpenDynaset)
For i = 1 To 50000
If apiGetAsyncKeyState(VK_ESCAPE) Then
If MsgBox("您要结束程序运行吗?", _
vbYesNo, "提示") = vbYes Then
Exit For
End If
End If
With rs
.AddNew
!Field1 = i
!Field2 = i * 2
!Field3 = i * 3
.Update
End With
Next
rs.Close
Set rs = Nothing
MsgBox "运行结束. 已添加 " & i-1 & " 条记录!"
End Function