MS Access VBA newbie here ...
我尝试运行MS Access 2010 VBA模块,将新的pdf报告导出到共享位置。该代码会为每个" ICB_NAME创建一个新报告。"但是,当我运行报告时,我收到以下错误:
运行时错误' 3014':无法再打开表格。
这是VBA:
Public Function exportbd()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim mypath As String
Dim temp As String
mypath = "S:\BD\" & Format(Date, "mm-dd-yyyy") & "\"
If Dir(mypath, vbDirectory) = "" Then MkDir mypath
Set db = CurrentDb()
Set rs = CurrentDb.OpenRecordset("SELECT eff_date, batch, jrnl, ledger, entity, account, interco, trans_amt, description, icb_name, combo FROM [BD Activity]", dbOpenDynaset)
Do While Not rs.EOF
temp = rs("ICB_NAME")
MyFileName = rs("ICB_NAME") & "-" & Format(Date, "mm-dd-yyyy") & ".PDF"
DoCmd.OpenReport "BD Settlement Report", acViewReport, , "[ICB_NAME]='" & temp & "'"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "BD Settlement Report"
rs.MoveNext
Loop
Set rs = Nothing
Set db = Nothing
End Function
我的预感是代码循环次数太多,因此会打开过多的表,这会使程序过载。我已经尝试过搞乱这个循环但是还没有能够纠正这个问题。我的诊断是否正确?有什么想法吗?