473,787 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.0 3.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 9338
Ok, I'm part way there:

Dim FileName As String

DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & 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*******@gmai l.comwrote in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
Ok, I'm part way there:

Dim FileName As String

DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & 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...@localh ost.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...@gmai l.comwrote in message

news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & 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 DailyOrderNumbe r

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

DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & Format(Date, "yyyy_mm_dd ") & "\" &
Format(Date, "yyyy_mm_dd ") & "." & DailyOrderNumbe r & " " & 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...@localh ost.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...@gmai l.comwrote in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & 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 DailyOrderNumbe r

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

DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & Format(Date, "yyyy_mm_dd ") & "\" &
Format(Date, "yyyy_mm_dd ") & "." & DailyOrderNumbe r & " " & 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\DR NOD\" & Format(Date, "yyyy_mm_dd ")
MkDir (DirectoryTest)

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

Egress:
Exit Sub

GenerateHighlin e_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*******@gmai l.comwrote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
On Mar 22, 4:22 pm, dancol...@gmail .com wrote:
>On Mar 22, 3:16 pm, "Larry Linson" <boun...@localh ost.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...@gmai l.comwrote in message
>news:11******* *************** @n76g2000hsh.go oglegroups.com. ..
Ok, I'm part way there:
Dim FileName As String
DoCmd.OpenRepor t "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & 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 DailyOrderNumbe r

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

DoCmd.OpenRepo rt "Report Export", acViewPreview, , , acIcon
FileName = "f:\Research\DR NOD\" & Format(Date, "yyyy_mm_dd ") & "\" &
Format(Date, "yyyy_mm_dd ") & "." & DailyOrderNumbe r & " " & Reports!
[Report Export]![BillLastName] & ".rtf"
DoCmd.Output To 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\DR NOD\" & Format(Date, "yyyy_mm_dd ")
MkDir (DirectoryTest)

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

Egress:
Exit Sub

GenerateHighlin e_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
6133
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 replaces the existing worksheet. Is there any way to get OutputTo to create more than one worksheet?
5
24205
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 like to save it to "My Documents". We have had some problems with our database crashing. We would therefore like another way to have access to basic student data and thought we automatically save the results of this query when we close Access. Any suggestions on how we could do this would be...
7
2922
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 looked in A97 HELP for the TransferSpreadsheet Action but there was no example code (Example appeared at the top next to 'See Also' but it was grayed out).
3
2396
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 cmdActiveListByEmployeeID_Click() On Error GoTo Err_cmdActiveListByEmployeeID_Click DoCmd.OutputTo acOutputReport, "AlphaListing", acFormatXLS, , True Exit_cmdActiveListByEmployeeID_Click: Exit Sub
5
2582
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 your search for "templatefile" Has anyone ever seen any specification for HTML templatefile microsoft says can be used in conjunction with the SendObject and OutPutTo methods - anywhere on the web? Publications or manuals? A friend or a cousin that may know something or someone?
3
7638
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 introduce a variable. Now that I've introduced the variable, I'm having problems. It is presenting the error listed below on the last line in my code section below. ERROR: Method ‘Open’ of object ‘Workbooks’ failed Dim xlApp As New Excel.Application Dim wbk As Excel.Workbook
1
1804
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 and there are no permission problems? Isn't a save command implied with the outputto command? Private Sub DisplayReport() Dim rptSls As Report
3
10978
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 I select the query then choose File/Export from the menu bar, choose "Text" as the save format, and then select "fixed width" as the export format, I end up with a fixed width text file with no column headers. I've tried to automate the process using: DoCmd.OutputTo acOutputQuery,...
4
5652
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 View, however, when I "OutputTo" this report to "Rich Text Format (*.rtf)", the colour is lost on the resultant RTF document when I open it up in Word 2007. I would obviously like to retain the colours dictated by my Conditional Formatting criteria results when I output this report to RTF format....
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.