|
本帖最后由 a63521557 于 2016-8-20 22:12 编辑
同一程序,在Access 2007及其以上版本中,在循环批量处理“子窗体/子报表”数据时,处理到198条记录后,弹出错误信息“您不能转到指定的记录”,并中止继续处理,而在Access 2003版本下运行则正常。
示例程序源代码:
Option Compare Database
Private Sub Form_Current()
DoCmd.Restore
End Sub
Private Sub Command01_Click()
On Error GoTo Err_Command01_Click
Dim strSQL, stDocName As String
Dim fgh, zjl, jls, wjs, js, js1, js2 As Long
For fgh = 1 To 9
If DCount("*", "CX18_发送短信数据", "[分工号]=" & fgh) > 0 Then
Me.查询表.SourceObject = ""
strSQL = "Delete * from 短信"
DoCmd.RunSQL strSQL
strSQL = "INSERT INTO 短信 SELECT CX18_发送短信数据.* FROM CX18_发送短信数据 WHERE [分工号]=" & fgh
DoCmd.RunSQL strSQL
Me.查询表.SourceObject = "表.短信"
Me.查询表.SetFocus
DoCmd.GoToRecord , , acFirst
Do While Me.查询表.Form.Recordset.RecordCount > Me.查询表.Form.CurrentRecord
Me.查询表.Form!编号 = Me.查询表.Form.CurrentRecord
DoCmd.GoToRecord , , acNext
Loop
Me.查询表.Form!编号 = Me.查询表.Form.CurrentRecord
DoCmd.GoToRecord , , acFirst
zjl = Me.查询表.Form.Recordset.RecordCount '总记录
jls = DLookup("[数值]", "数据常量", "[计算常量] = '短信每页数'") '页记录数
wjs = Int(zjl / jls) + IIf(zjl / jls > Int(zjl / jls), 1, 0) '文件数
For js = 1 To wjs
stDocName = Mid(CurrentProject.Name, 1, 4) & "年" & Mid(CurrentProject.Name, 5, 2) & "月工资短信数据" & fgh & "-" & wjs & "-" & js
js1 = (js - 1) * jls + 1
js2 = IIf(js = wjs, zjl, js * jls)
strSQL = "SELECT 移动电话, 发送短信 FROM 短信 WHERE 编号>=" & js1 & " And 编号<=" & js2
VBAJB (strSQL)
DoCmd.TransferSpreadsheet acExport, 8, "00_临时数据查询", CurrentProject.Path & "\" & stDocName & ".xls", False
MsgBox " 已完成(" & CurrentProject.Path & "\" & stDocName & ".xls)" & vbLf & vbLf _
& "文件的导出,请修改其文件以适应短信发送!", vbOKOnly + vbInformation, "操作提示"
Next js
End If
Next fgh
Exit_Command01_Click:
Exit Sub
Err_Command01_Click:
MsgBox Err.Description
Resume Exit_Command01_Click
End Sub
Private Sub Form_Close()
Dim strSQL As String
strSQL = "Delete * from 短信"
CurrentDb.Execute strSQL
End Sub
'创建临时数据表
Public Function VBAJB(strSQL As String)
Dim i As Integer
'删除 00_临时数据查询
For i = 0 To CurrentDb.QueryDefs.Count - 1
If CurrentDb.QueryDefs(i).Name = "00_临时数据查询" Then
DoCmd.DeleteObject acQuery, CurrentDb.QueryDefs(i).Name
Exit For
End If
Next i
'创建 00_临时数据查询
CurrentProject.Connection.Execute "Create View 00_临时数据查询 as " & strSQL
End Function
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|