提问人:Tommy 提问时间:7/13/2023 更新时间:7/13/2023 访问量:20
如何将访问报告保存为带有变量名称的 pdf 并让用户选择位置?
How can i save a access report to pdf with a variable name and let the user choose the location?
问:
我想将访问报告保存为具有特定名称的 pdf(从表单中获取),但用户仍然可以选择保存它的位置。
我可以使用报告的标准名称保存报告,我可以使用表单的特定名称保存报告,但是代码中不再有“文件名”一词,并且没有弹出窗口可以保存 从我尝试将字符串与单词“文件名”组合在一起的那一刻起,我认为访问会做一些事情,但我无法读取什么,因为它会很快消失并且无法在任何地方找到我的文件。
我尝试的最后一个男女同校是这个,我想我尝试了所有组合,但我找不到它 请帮忙:
Private Sub KnPdoductieopdrachtPDF_Click()
Dim strReportName As String
Dim strPathName As String
Dim Locname As String
strReportName = "Productieopdracht" & [Taaknummer] & ".pdf"
strPathName = Filename
Locname = strPathName & strReportName
DoCmd.OutputTo acOutputReport, "Productieopdracht R", acFormatPDF, Locname, False, "", , acExportQualityPrint
End Sub
答:
0赞
Gustav
7/13/2023
#1
添加对 Microsoft Office 16.0 对象库的引用,并使用 FileDialogue:
' Open the file dialogue for the user to select a folder.
' Returns the folder name chosen or an empty string if the user cancelled.
'
' 2023-03-31. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function SelectFolderName( _
Optional ByVal InitialFolderName As String, _
Optional ByVal Title As String) _
As String
Const DefaultTitle As String = "Select folder"
Dim FileDialog As FileDialog
Dim FolderName As String
Set FileDialog = Application.FileDialog(msoFileDialogFolderPicker)
If Trim(Title) = "" Then
Title = DefaultTitle
End If
FileDialog.Title = Title
FileDialog.InitialFileName = InitialFolderName
FileDialog.AllowMultiSelect = False
FileDialog.Filters.Clear
FileDialog.Show
If FileDialog.SelectedItems.Count = 0 Then
' User cancelled.
Else
FolderName = FileDialog.SelectedItems(1)
End If
Set FileDialog = Nothing
SelectFolderName = FolderName
End Function
然后使用文件名构建要保存的 PDF 文件的完整路径。
评论
0赞
Tommy
7/16/2023
我把你的代码放在哪里?因为我试图把它放在按钮上,但后来我收到错误,说 sub 必须结束于你的代码之上,如果我把你的代码放在 sub 之上,我会在输出的子代码上出错,他不认识我认为 foldername 。
0赞
Gustav
7/16/2023
把它放在一个(新)模块中,而不是表单的模块中。
上一个:检索此数据的最佳方法是什么?
下一个:将文件保存到文件夹
评论