Dynamic Report Name??

caracena

New member
Local time
Today, 14:16
Joined
May 14, 2008
Messages
8
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,
 
I got this to do the trick Caracena...
Code:
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
 
Full Code that Works

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

Code:
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
 

Users who are viewing this thread

Back
Top Bottom