View Full Version : Format Date Via Code


geraldcor
05-11-2006, 02:43 PM
Hello All,
I have a nifty automatic pdf printing scheme set up using pdf995. I use criteria from the reports themselves to name the output files for the pdf. On one of the reports they want the date to be a part of the filename. When I try to base it on a date field on a form (the form where the reports are being printed from) the print to pdf fails because the date format is 05/11/2006. I cannot have the slashes in the filename. I formated the textbox with the date to dd mmm yyyy so it shows up formatted correctly but I gues when it is pulling the info for the pdf it pulls the standard slash format thus the pdf will not print. So, how can I make it so access or better yet pdf995 recognizes the date in a filename friendly format? VBA, or other? Thank you all for your help.

Greg

KenHigg
05-11-2006, 02:51 PM
Can you convert the date to a string before you use it?

geraldcor
05-11-2006, 02:57 PM
Yes I can do that, then how do I format it properly? I tried just making it a string and then making that string = to the date textbox. That didn't work of course.

KenHigg
05-11-2006, 02:59 PM
Hum... Did you format it before you converted it?

geraldcor
05-11-2006, 03:05 PM
I am just formating it on the form in the properties, then converting it when the user clicks a command button to print to pdf.

KenHigg
05-11-2006, 03:07 PM
Are you naming the file in a pc of code somewhere?

geraldcor
05-11-2006, 03:14 PM
pc of code?
The format is
Call PrintPDFStatements(stDocName1, "IDFL Statement " & dateformat)
PrintPDFStatements in a module that creates a folder if one doesn't exist and makes sure the criteria is the same then it calls another portion of the module that does the actual printing. stDocName1 is the report name in access and the stuff followint the "," is the filename.

KenHigg
05-11-2006, 03:18 PM
Does 'dateformat' contain the date you need to use?

geraldcor
05-11-2006, 03:20 PM
Oh yeah forgot that. That is the string of the date.

KenHigg
05-11-2006, 03:26 PM
So can you convert it to a string there? (fyi:Not so good a name for a variable:))

KenHigg
05-11-2006, 03:28 PM
Got to run... Good luck :) :)

geraldcor
05-11-2006, 04:10 PM
Here is what I did and it works wonderfully (I tried a bunch of different ways to format the date and this is the one that the users liked)
Call PrintPDFStatements(stDocName3, "IDFL Statement " & Format$(stdateformat, "mm-dd-yy"))
It ends up being formated as 05-11-06. Thanks for your help Ken, this isn't the first time.

Greg