472,325 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

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 9156
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy Harris | last post by:
I'm using OutputTo to send data into Excel. It has been working nicely. Now, I need to add more worksheets using OutputTo. Whenever I use it, it...
5
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would...
7
by: MLH | last post by:
A97 has menu options that support exporting table data to ms excel data file format. Is this easily implemented from within code? Any examples? I...
3
by: lushh | last post by:
hi guys. i am currently using ms access 2003. i want to export my reports to an excel file so i did a code like this: Private Sub...
5
by: MLH | last post by:
Searching at http://support.microsoft.com/search/?adv=0 for Access 97 and "templatefile" returns the following: There are no documents that match...
3
dbushcmohle
by: dbushcmohle | last post by:
Hello, I am having problems exporting a stored procedure's results to an Excel file... I've done this many times successfully, but never had to...
1
by: pdxrichard | last post by:
Windows XP - Server 2003 - Access 2007 VBA - Code behind a form Here is my code. Why can't I find the exported file if the directories exist...
3
by: Wayne | last post by:
I'm trying to automate the export of a query to a text file using code. If I export the query manually I get the exact result that I want i.e. If...
4
by: riaane | last post by:
Please help: I have Conditional Formatting on a Report Field that fills the background Red if the criteria is met. This displays correctly in Report...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.