Hi all,
I need help with the following. I have a number of forms that have several fields, 2 of these specific forms are used for a report, report and subreport. I need the file dialog box for exporting the report as a pdf to auto-populate the report name based on 2 fields on these forms. so far I have managed to export the report into the pdf without auto-populating the desired file name. Whenever I use my code below it auto-populates the name as I want it to but the code throws an error and because of my error handler code it closes the database.
Please be advised that my code is not pretty, I graduated from Google and been able to get this far by doing a lot of searching.
first code is the one that auto-populates the name but throws a code and does not export as a pdf, while also closing the database
second code is the one that does export and throws no errors, but does not auto-populate the file name when exporting
I need help with the following. I have a number of forms that have several fields, 2 of these specific forms are used for a report, report and subreport. I need the file dialog box for exporting the report as a pdf to auto-populate the report name based on 2 fields on these forms. so far I have managed to export the report into the pdf without auto-populating the desired file name. Whenever I use my code below it auto-populates the name as I want it to but the code throws an error and because of my error handler code it closes the database.
Please be advised that my code is not pretty, I graduated from Google and been able to get this far by doing a lot of searching.
first code is the one that auto-populates the name but throws a code and does not export as a pdf, while also closing the database
second code is the one that does export and throws no errors, but does not auto-populate the file name when exporting
Code:
Private Sub Command22_Click()
Dim fileName As String, strFullpath As String
Dim answer As Integer
Dim fileName2 As String
Dim strFile As String
Dim intPos As Integer
Dim strRptName As String
On Error GoTo error1
DoCmd.OpenForm "Specific_Information_frm"
'filename for PDF file*
strRptName = Forms![Specific_Information_frm]![WBS Number] & " " & "Ultrasonic Report"
strFullpath = BrowseFile
If strFullpath <> "" Then
' get folder and file names
intPos = InStrRev(strFullpath, "\")
strFolder = Left(strFullpath, intPos - 1)
strFile = Mid(strFullpath, intPos + 1)
'folder path where pdf file will be saved *
End If
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=strRptName, outputformat:=acFormatPDF, outputFile:=strFullpath
DoCmd.Close acForm, "Specific_Information_frm"
DoCmd.Close acReport, "C-Scan_rpt"
MsgBox prompt:="PDF File succesfully exported to desired location ", buttons:=vbInformation, Title:="Report Exported as PDF"
Exit Sub
error1:
MsgBox prompt:="An Error has occurred. Closing Database Now", buttons:=vbCritical
DoCmd.Quit
End Sub
Code:
Private Sub Command22_Click()
Dim fileName As String, strFullpath As String
Dim answer As Integer
Dim fileName2 As String
Dim strFile As String
Dim intPos As Integer
On Error GoTo error1
DoCmd.OpenForm "Specific_Information_frm"
'filename for PDF file*
fileName = "C-Scan Report"
fileName2 = Forms![Specific_Information_frm]![WBS Number]
strFullpath = BrowseFile
If strFullpath <> "" Then
' get folder and file names
intPos = InStrRev(strFullpath, "\")
strFolder = Left(strFullpath, intPos - 1)
strFile = Mid(strFullpath, intPos + 1)
'folder path where pdf file will be saved *
End If
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=strFullpath
DoCmd.Close acForm, "Specific_Information_frm"
DoCmd.Close acReport, "C-Scan_rpt"
MsgBox prompt:="PDF File succesfully exported to desired location ", buttons:=vbInformation, Title:="Report Exported as PDF"
Exit Sub
error1:
MsgBox prompt:="An Error has occurred. Closing Database Now", buttons:=vbCritical
DoCmd.Quit
End Sub