保存按钮运行时错误 [英] Save Button Run-Time Error

查看:82
本文介绍了保存按钮运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份名为"每周时间表"的报告。显示前几周的员工工时。 

I have a report named "WEEKLY TIME SHEET" that displays the previous weeks employee hours. 

此报告基于我的查询"HOURS QUERY"其中包含以下字段:

- 日期

- 员工

- 开始时间

- 完成时间

- HOURS:IIf(DateDiff(" n",[START TIME],[FINISH TIME])> 0,DateDiff(" n",[START TIME],[FINISH TIME]), DateDiff("n",[START TIME],[FINISH TIME])+ 1440)/ 60

- 周结束:[DATE] +(7-Weekday([DATE],7))

年([DATE])* 53 + DatePart("ww",[DATE])

This report is based on my query "HOURS QUERY" which has the following fields:
- DATE
- EMPLOYEE
- START TIME
- FINISH TIME
- HOURS: IIf(DateDiff("n",[START TIME],[FINISH TIME])>0,DateDiff("n",[START TIME],[FINISH TIME]),DateDiff("n",[START TIME],[FINISH TIME])+1440)/60
- WEEK ENDING: [DATE]+(7-Weekday([DATE],7))
Year([DATE])*53+DatePart("ww",[DATE])

在我的报告中,我创建了一个按钮来保存它作为PDF文件,在指定的位置,我希望它以周结束作为文件名保存。我的代码是:

On my report I have created a button to save it as a PDF file, in a specified location, and I want it to save it with the Week Ending as the file name. The code that I have is:

Private Sub SAVE_Click()

Dim strFileName As String

strFileName =" Z:\ OLOME CSCS TEST CENTER 01-03-18\\\\\\\\\\\\\\\\\\\\\\\\\\\\ &安培; " WE" &安培; " " &安培; WEEK_ENDING& " .PDF"

DoCmd.OutputTo acOutputReport,"WEEKLY TIME SHEET",acFormatPDF,strFileName

Dim strFileName As String strFileName = "Z:\FROME CSCS TEST CENTRE 01-03-18\2.0 ADMINISTRATION\2.9 WORK HOURS\" & "WE" & " " & WEEK_ENDING & ".pdf" DoCmd.OutputTo acOutputReport, "WEEKLY TIME SHEET", acFormatPDF, strFileName

End Sub

我一直收到运行时错误"OutputTo操作已取消。"

I keep getting a run-time error "The OutputTo action was cancelled."

现在如果我拿出代码的WEEK_ENDING部分,它有效,所以我很确定它必须与那部分有关,我想我已经发现它是因为它试图以dd格式保存短划线mm / yyyy,你不能在文件名中使用/。

Now if I take out the WEEK_ENDING part of the code, it works, so I'm pretty sure it must be to do with that part, and I think I've figured out that it's because it's trying to save the dash in the format dd/mm/yyyy, and you can't use / in file names.

我在报告和查询中将DATE和WEEK ENDING格式都改为dd-mm-yy,但是当你将鼠标悬停在VBA中的WEEK_ENDING上时,它仍会以dd / mm / yyyy格式显示。 

I've changed both the DATE and WEEK ENDING format to dd-mm-yy in the Report and the Query, but when you hover over WEEK_ENDING in VBA, it still shows it in the dd/mm/yyyy format. 

我该如何解决这个问题?

How can I work around this?

推荐答案

管理以解决我自己的问题! 

Managed to fix my own problem! 

保留这个问题并发布答案以防其他人帮助。

Will keep this question and post the answer in case it helps anybody else.

在我添加的查询中新字段:

In the query I added the new field:

- 周末:(格式([WEEK ENDING],"dd-mm-yy"))

- WEEK END: (Format([WEEK ENDING],"dd-mm-yy"))

然后在VBA代码中将WEEK_ENDING更改为WEEK_END,它现在保存为"WE 01-06-18"

And then changed the WEEK_ENDING to WEEK_END in the VBA code and it now saves as "WE 01-06-18"


这篇关于保存按钮运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆