Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Home > Forums > Access Forum > Access report by David Hilliard
Back to Access Forum    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
Access report
David Hilliard 
   
3 years ago
I need to generate PDFs for my reports, but I need each PDF to be named as the first & last name of each person I generate a PDF for. I imagine there is a simple VBA code to do this but I don't know how.
Kevin Robertson  @Reply  
          
3 years ago
How about this:

Dim Filename As String, Dest As String

Filename = FirstName & "-" & LastName & ".pdf"
Dest = CurrentProject.Path & "\" & Filename
    
DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, Dest
David Hilliard OP  @Reply  
   
3 years ago
It still doesn't recognize FirstName. My 2 versions of the code:

1 (what you sent me)
Dim Filename As String, Dest As String

Filename = FirstName & "-" & LastName & ".pdf"
Dest = CurrentProject.Path & "\" & Filename
    
DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, Dest

-----------
2
Dim Filename As String, Dest As String

Filename = FirstName & "-" & LastName & ".pdf"
Dest = CurrentProject.Path & "\" & Filename
    
DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, Dest

End Sub
-----
Do I need to tell VBA what file I"m FirstName from?
Richard Rost  @Reply  
          
3 years ago
"It still doesn't recognize" doesn't tell us anything. What's happening? Let's see some screen shots of your code in place, and what happens when you run it.
David Hilliard OP  @Reply  
   
3 years ago
Dear Richard,

All I want to do is when I print a statement as a PDF I want it's filename to be the current customer's first and last name. I'm sure it's simple, but I don't know how.

Thanksso much for your help.
Kevin Robertson  @Reply  
          
3 years ago
Is FirstName on your form? If it is and Access doesn't recognise it check your spelling.
Richard Rost  @Reply  
          
3 years ago
What's happening when you use what you have?
Scott Axton  @Reply  
      
3 years ago
1st
Did you substitute your actual report name for "YourReportName"?
In other words if your report is QuarterlyCustomerInfoR you would have to put that in place of "YourReportName"

DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, Dest
to
DoCmd.OutputTo acOutputReport, "QuarterlyCustomerInfoR", acFormatPDF, Dest

2nd
No, you shouldn't need to specify where FirstName comes from.  It does however have to be in the Record Source for the report.

3rd
If your Field Names contain spaces you must enclose them in square brackets.

FirstName   Good
First Name  needs brackets  [First Name]
Richard Rost  @Reply  
          
3 years ago
Works perfectly for me:

    Dim FN, LN, Filename
    FN = Forms!CustomerF!FirstName
    LN = Forms!CustomerF!LastName
    Filename = CurrentProject.Path & "\" & FN & "-" & LN & ".PDF"
    DoCmd.OutputTo acOutputReport, "OrderInvoiceR", acFormatPDF, Filename

Richard Rost  @Reply  
          
3 years ago

Richard Rost  @Reply  
          
3 years ago
Even if I put a space in the first name value...
Richard Rost  @Reply  
          
3 years ago

Richard Rost  @Reply  
          
3 years ago
Let's see what is happening EXACTLY on your system. Post screen shots of your code and the results.
Richard Rost  @Reply  
          
3 years ago
Review Export Reports to PDF and if you're trying to loop with VBA to export multiple reports, see Access Developer 17.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 10/16/2026 10:25:04 AM. PLT: 1s