469,290 Members | 1,880 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Formatting File Names for OutputTo

I have a question regarding the DoCmd.OutputTo function.

I have an invoice report that shows all of the invoices for a
particular date. I want to create a button that will export each page
of the report (i.e. each separate invoice) as a separate RTF file, and
save each file with the date, a sequential number (starting with 01
for the first invoice on that date), and the value of the LastName
field for that particular invoice in the filename, so something like:

20070322_Smith.01.rtf
20070322_Jones.02.rtf
20070322_Cole.03.rtf

So how do I do that?

My biggest weakness in Access is how to properly format this sort of
thing, so please include examples in your response. I really
appreciate it!

Thanks!

-Dan

Mar 22 '07 #1
5 8751
Ok, I'm part way there:

Dim FileName As String

DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "." &
"01" & " " & Reports![Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"
Of course, instead of "01" I want it to give me a sequential number.
And obviously this exports the entire report as one file. And it names
the file as whatever the first page's BillLastName value is.

Thoughts?

Mar 22 '07 #2
AFAIK, there is no capability to access individual pages of a report, as
you wish.

You might use a query that limits the data to that which would appear on a
single page, and, in VBA code, modify the query for each page and execute a
report for that page only, until you have completed the list of pages you
want to save.

Alternatively, it might be as simple to control Microsoft Word though COM
automation, and create the "reports" in that manner.

Either of these will require competence with VBA code, and though not
"rocket science", neither is "trivially simple", either. Finally, neither,
IMNSHO, can be adequately covered in a newsgroup response.

Larry Linson
Microsoft Access MVP
<da*******@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
Ok, I'm part way there:

Dim FileName As String

DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "." &
"01" & " " & Reports![Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"
Of course, instead of "01" I want it to give me a sequential number.
And obviously this exports the entire report as one file. And it names
the file as whatever the first page's BillLastName value is.

Thoughts?

Mar 22 '07 #3
On Mar 22, 3:16 pm, "Larry Linson" <boun...@localhost.notwrote:
AFAIK, there is no capability to access individual pages of a report, as
you wish.

You might use a query that limits the data to that which would appear on a
single page, and, in VBA code, modify the query for each page and execute a
report for that page only, until you have completed the list of pages you
want to save.

Alternatively, it might be as simple to control Microsoft Word though COM
automation, and create the "reports" in that manner.

Either of these will require competence with VBA code, and though not
"rocket science", neither is "trivially simple", either. Finally, neither,
IMNSHO, can be adequately covered in a newsgroup response.

Larry Linson
Microsoft Access MVP

<dancol...@gmail.comwrote in message

news:11**********************@n76g2000hsh.googlegr oups.com...
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "." &
"01" & " " & Reports![Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"
Of course, instead of "01" I want it to give me a sequential number.
And obviously this exports the entire report as one file. And it names
the file as whatever the first page's BillLastName value is.
Thoughts?
Fair enough.

Ok, how about this (ignore my previous questions)... I want my
OutputTo command to put the files in a new directory. It won't do it
if I just tell it to OutputTo a directory that doesn't exist. How to I
get Access to do THIS:
------------------------------
If DirectoryX isn't there, create DirectoryX
OutputTo DirectoryX

If Directory X is there, OutputTo DirectoryX
-----------------------------

My code (produced entirely by trial and error) as it stands looks like
this:

Dim FileName As String
Dim DailyOrderNumber

Forms![Batch]![OrderCounter] = 1 + Forms![Batch]![OrderCounter]
DailyOrderNumber = Format(Forms![Batch]![OrderCounter], "00")

DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "\" &
Format(Date, "yyyy_mm_dd") & "." & DailyOrderNumber & " " & Reports!
[Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"
Thanks for all your help!

Mar 22 '07 #4
On Mar 22, 4:22 pm, dancol...@gmail.com wrote:
On Mar 22, 3:16 pm, "Larry Linson" <boun...@localhost.notwrote:
AFAIK, there is no capability to access individual pages of a report, as
you wish.
You might use a query that limits the data to that which would appear on a
single page, and, in VBA code, modify the query for each page and execute a
report for that page only, until you have completed the list of pages you
want to save.
Alternatively, it might be as simple to control Microsoft Word though COM
automation, and create the "reports" in that manner.
Either of these will require competence with VBA code, and though not
"rocket science", neither is "trivially simple", either. Finally, neither,
IMNSHO, can be adequately covered in a newsgroup response.
Larry Linson
Microsoft Access MVP
<dancol...@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "." &
"01" & " " & Reports![Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"
Of course, instead of "01" I want it to give me a sequential number.
And obviously this exports the entire report as one file. And it names
the file as whatever the first page's BillLastName value is.
Thoughts?

Fair enough.

Ok, how about this (ignore my previous questions)... I want my
OutputTo command to put the files in a new directory. It won't do it
if I just tell it to OutputTo a directory that doesn't exist. How to I
get Access to do THIS:

------------------------------
If DirectoryX isn't there, create DirectoryX
OutputTo DirectoryX

If Directory X is there, OutputTo DirectoryX
-----------------------------

My code (produced entirely by trial and error) as it stands looks like
this:

Dim FileName As String
Dim DailyOrderNumber

Forms![Batch]![OrderCounter] = 1 + Forms![Batch]![OrderCounter]
DailyOrderNumber = Format(Forms![Batch]![OrderCounter], "00")

DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "\" &
Format(Date, "yyyy_mm_dd") & "." & DailyOrderNumber & " " & Reports!
[Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"

Thanks for all your help!
I think I figured it out...

I just added the following code to the beginning and end:

On Error GoTo Generate_Error

DirectoryTest = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd")
MkDir (DirectoryTest)

------------------------------

Egress:
Exit Sub

GenerateHighline_Error:
Select Case Err.Number
Case 75
Resume Next
Case Else
MsgBox Err.Description
Resume Egress
End Select

Mar 22 '07 #5
Glad to see you got it working.

Now I have thought of one possible approach to dealing with "pages of a
report"... export the Report from Preview to HTML format, and that will
generate one HTML file per page. That's not exactly what you wanted, but it
does allow doing something with "pages" of the report, after the fact. And,
it my experience, the HTML maintains the formatting somewhat better than
..RTF.

I had a colleague who used HTML reports to make data available to a wide
audience of people in a large organization, all of whom had some capability
to view HTML, but whose IT department did not want to install the Snapshot
Reader nor Adobe Acrobat Reader, and relatively few of whom had Access
installed.

Larry Linson
Microsoft Access MVP

<da*******@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On Mar 22, 4:22 pm, dancol...@gmail.com wrote:
>On Mar 22, 3:16 pm, "Larry Linson" <boun...@localhost.notwrote:
AFAIK, there is no capability to access individual pages of a report,
as
you wish.
You might use a query that limits the data to that which would appear
on a
single page, and, in VBA code, modify the query for each page and
execute a
report for that page only, until you have completed the list of pages
you
want to save.
Alternatively, it might be as simple to control Microsoft Word though
COM
automation, and create the "reports" in that manner.
Either of these will require competence with VBA code, and though not
"rocket science", neither is "trivially simple", either. Finally,
neither,
IMNSHO, can be adequately covered in a newsgroup response.
Larry Linson
Microsoft Access MVP
<dancol...@gmail.comwrote in message
>news:11**********************@n76g2000hsh.googleg roups.com...
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "." &
"01" & " " & Reports![Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF,
FileName,
False
DoCmd.Close acReport, "Report Export"
Of course, instead of "01" I want it to give me a sequential number.
And obviously this exports the entire report as one file. And it
names
the file as whatever the first page's BillLastName value is.
Thoughts?

Fair enough.

Ok, how about this (ignore my previous questions)... I want my
OutputTo command to put the files in a new directory. It won't do it
if I just tell it to OutputTo a directory that doesn't exist. How to I
get Access to do THIS:

------------------------------
If DirectoryX isn't there, create DirectoryX
OutputTo DirectoryX

If Directory X is there, OutputTo DirectoryX
-----------------------------

My code (produced entirely by trial and error) as it stands looks like
this:

Dim FileName As String
Dim DailyOrderNumber

Forms![Batch]![OrderCounter] = 1 + Forms![Batch]![OrderCounter]
DailyOrderNumber = Format(Forms![Batch]![OrderCounter], "00")

DoCmd.OpenReport "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd") & "\" &
Format(Date, "yyyy_mm_dd") & "." & DailyOrderNumber & " " & Reports!
[Report Export]![BillLastName] & ".rtf"
DoCmd.OutputTo acOutputReport, "Report Export", acFormatRTF, FileName,
False
DoCmd.Close acReport, "Report Export"

Thanks for all your help!

I think I figured it out...

I just added the following code to the beginning and end:

On Error GoTo Generate_Error

DirectoryTest = "f:\Research\DRNOD\" & Format(Date, "yyyy_mm_dd")
MkDir (DirectoryTest)

------------------------------

Egress:
Exit Sub

GenerateHighline_Error:
Select Case Err.Number
Case 75
Resume Next
Case Else
MsgBox Err.Description
Resume Egress
End Select

Mar 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Randy Harris | last post: by
5 posts views Thread by MLH | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.