1

I am currently in the process of generating a report in access which, once generated, should be saved to a save location to user puts in.

Here's my block of code.

ReportName = "Appraisal_" & Trim(Str(Year)) & "_" & Me.empnr & "_" & Veilig(Me.empnr) & "_" & Format(Now(), "YYYY_MM_DD_HH_MM_SS")
DoCmd.CopyObject , ReportName , acReport, "rpt_beoordelen"
DoCmd.OpenReport ReportName , acViewPreview, , "EmployeeNr='" & Me.empnr & "'  and year=" & Me.Year
DoCmd.OutputTo acOutputReport, "", acFormatPDF, , True
DoCmd.Close acReport, ReportName 

This generates and displays the report with the correct values. It asks for save location. And, once given, tries to save the file to given location. It quickly flashes a printing PDF to give location window.

After this the program stops. No file can be found at the given location and the report is still opened. Debugging the application shows me that

DoCmd.Close acReport, ReportName

is never reached. I do not get a errormessage and i have no clue what is going wrong. Could anyone give me a solution to this problem?

4

1 回答 1

0

如果您无法DoCmd.OutputTo通过将“活动对象”ObjectName留空(参考:此处)来使用“活动对象”,那么您可以尝试以下操作:

打开“rpt_beoordelen”报告并将其Record Source查询保存为名为“rpt_beoordelen_base_data”的已保存查询。使用一些通用 SQL 创建一个“rpt_beoordelen_data”保存的查询,例如...

SELECT * FROM rpt_beoordelen_base_data

Record Source...然后为 [rpt_beoordelen] 报告制作“rpt_beoordelen_data” 。

现在将代码从您的问题更改为如下所示:

ReportName = "Appraisal_" & Trim(Str(Year)) & "_" & Me.empnr & "_" & Veilig(Me.empnr) & "_" & Format(Now(), "YYYY_MM_DD_HH_MM_SS")
DoCmd.CopyObject , ReportName , acReport, "rpt_beoordelen"
Dim cdb As DAO.Database
Set cdb = CurrentDb
Dim qdf As DAO.QueryDef
Set qdf = cdb.QueryDefs("rpt_beoordelen_data")
qdf.SQL = "SELECT * FROM rpt_beoordelen_base_data WHERE EmployeeNr='" & Me.empnr & "'  and year=" & Me.Year
Set qdf = Nothing
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF

这会将您的调用更改DoCmd.OutputTo为不依赖于“活动对象”的调用,并且可能会产生您想要的结果。(FWIW,这是我使用这种方法生成 PDF 版本报告的唯一方法。)

于 2013-04-21T23:04:30.580 回答