caracena
05-14-2008, 02:16 PM
Hello all,
I am interested on having a name the report (which comes in a very nice looking pop up window) that matches a combination of a fixed phrase plus 2 variables so when I send it to the PDF printer, I only have to select the right location to store it.
With this, I want to avoid 2 things: waste time and above all, avoid a human mistake if I or someone else types the wrong invoice number.
I know this is an easy thing to do but I don't have the slightles idea where to start :eek:
Thanks a lot in advanced,
MrRundog
05-15-2008, 02:02 PM
Me too - Please can someone give us a clue?
MrRundog
05-19-2008, 12:00 AM
I got this to do the trick Caracena...
Dim stFileName As String, stExtension As String
stFileName = Forms!frmClaimsParts!claimID
stExtension = ".pdf"
DoCmd.OutputTo acOutputReport, "rptParts", acFormatPDF, stFileName & stExtension
The code needs to be attached to a button and the buttons onClick event.
Does Anyone know how I can stipulate the path to save to - at the moment this goes to the last place any document was saved to without asking me where to save it to. Also - Is it possible to create a new folder with the same name as the report & save the pdf to that folder?
Cheers
MrRundog
05-19-2008, 12:34 AM
Ok - I have it figured - This works for me on XP & access 2007
Create New Folder And name as ReportName
Create Report PDF
Save to File (New Folder)
All in one operation - The Create File was obtained from this forum someplace so thanks to Kiwiman
Heres the code - I hop it helps someone out
Dim stFileName As String, stExtension As String, strName As String
Dim strFile As String, strFileName As String, lngRetval As String, strNewFilePath As String
strName = Me.claimID ' then name of the text box that holds your site
strFile = "C:\Reports\" ' default file location
strFileName = strFile & strName ' the full directory name
If Dir(strFileName, vbDirectory) <> "" Then
' Directory exists, insert your file output code here
Else
' Directory doesn't exist
' Prompt user if he wants it to be created
lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
If lngRetval = 6 Then
' User asked to create dir, so create it.
' Well, the nested directory doesn't exist, but need
' to check if the vbtemp exists to avoid similar error
If Dir(strFile, vbDirectory) <> "" Then
' Just create the sub-directory
MkDir (strFileName)
Else
' Create main and then sub-dir
MkDir (strFile)
MkDir (strFileName)
End If
' Check if it got created
If Dir(strFileName, vbDirectory) <> "" Then
' Let user know it was success
MsgBox ("Path created succesfully.")
Else
' Let user know it was failure
MsgBox ("Error creating path.")
End If
Else
' User asked not to create dir
MsgBox ("Path was not created.")
End If
End If
stExtension = ".pdf"
strNewFilePath = strFile & strName & "\" & strName
DoCmd.OutputTo acOutputReport, "rptParts", acFormatPDF, strNewFilePath & stExtension