save as pdf with date (1 Viewer)

bigmac

Registered User.
Local time
Today, 12:49
Joined
Oct 5, 2008
Messages
295
hi all can you help please?
I am trying to save a report via a button and a macro, this I have achieved.
but how do I get it to also save the time and date in the name of the pdf instead of just the name of the report?
example, report name "test" pdf needs to be called "test [todays date,time]":confused:
 

bigmac

Registered User.
Local time
Today, 12:49
Joined
Oct 5, 2008
Messages
295
sorry I do not understand what you mean ,
I save the report through a basic macro
object type "report"
object name "test"
outputformat "pdf format(*.pdf)"

this saves the report as a pdf called test but I need it to add the date and time to the name.
any ideas please?
 

bob fitz

AWF VIP
Local time
Today, 20:49
Joined
May 23, 2011
Messages
4,721
Sorry, I should have read your OP more carefully. I don't use macros, so I will be unable to help you with this.
 

bigmac

Registered User.
Local time
Today, 12:49
Joined
Oct 5, 2008
Messages
295
can you show me how to do this in vba?
 

vbaInet

AWF VIP
Local time
Today, 20:49
Joined
Jan 22, 2010
Messages
26,374
In the absence of bob fitz ;) ... you need to do this in VBA. So look into these three functions:

OutputTo(), Format() and Now().
 

bigmac

Registered User.
Local time
Today, 12:49
Joined
Oct 5, 2008
Messages
295
vbainet , thank you for your response but this is all above my head,
all I want is to be able to save a report as a pdf using the report name and adding the date to the name,
if this has to be done in vba then can you show me in an example how this is done ,iy will be better for me to follow and understand it.
 

Mike375

Registered User.
Local time
Tomorrow, 05:49
Joined
Aug 28, 2008
Messages
2,548
I just copied this from my own stuff but it is for Word

Forms!PrintAndClose!LetterName = ("" + Format(Now, "YYYY-MM-DD") + " " & Format(Now, "hh-mm-ss") + " " & ([Forms]![PrintAndClose]![CLSurname]) + " " & ([Forms]![PrintAndClose]![Text469]) + " " & "Not Printed" + ".doc")

That produces a Word doc file with a name like

2014-04-14 11-08-38 Albert AIG Not Printed

This is basically the VBA version of the Set Value in a macro. In other words the value of the field LetterName will be "set" to what is on the right hand side of the = sign.

However, the limit of the macro is you can't do what is on the right hand side of the equal sign. Although it might be possible in the later versions of Access such as 2013 and probably 2007.
 

vbaInet

AWF VIP
Local time
Today, 20:49
Joined
Jan 22, 2010
Messages
26,374
I did say to research these methods so some quick "Googling" would have returned plenty of examples. Skeleton code:
Code:
Dim strDocName As String

strDocName = "[COLOR="Blue"]\Path\to\file\here\[/COLOR]" & Format(Now(), "yyyymmdd_hhnn")

DoCmd.OutputTo "NameOfReport",
Research the OutputTo method to determine where to put strDocName and amend the bits in blue.

This code will go into the Click event of a button.
 

icbiny

Registered User.
Local time
Today, 20:49
Joined
May 15, 2012
Messages
15
put this code on a button...
DoCmd.OutputTo acOutputReport, "Reuse_Invoice", acFormatPDF, "e:\" & Me.Combo0.Column(1) & Me.Text2 & ".pdf"

Reuse_Invoice is the name of the report. after acFormatPDF, is the part u are asking about. here it simply builds a string e: is the location, combo0 is a combo box where the month is selected and text2 is a textbox with the year entered and finally .pdf is the file extension. The whole thing looks like "e:\September2014.pdf
you could easily have "c:\my folder\filename\" & date() & ".pdf"
 

Users who are viewing this thread

Top Bottom