Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling the Save As Dialog Box with VBA

Status
Not open for further replies.

Eutychus

Programmer
Nov 14, 2007
61
US
I want to use VBA to control the values in the "Save In," "File Name," and "Save as Type" text boxes when the Save As Dialog box pops up. I don't know how to refer to those text boxes to set their values. I also want to use VBA to "click" the Save button. I am using Access 2002-3 with Windows XP, but want this to work with Access 2003 on a Vista machine, too, with backend (tables) on a Windows 2003 server. Here is what I do:
1) On an Access form, the user clicks a "Print Report" button to print an Access report.
2) The code behind the button executes the DoCmd as follows:
stDocName = "My Report Name"
DoCmd.OpenReport stDocName, acViewPrint
3) The Save As dialog box pops up because the Page SetUp for the report has a Virtual PDF printer selected to save the report to a PDF file.
4) It is at this point that I want to control the values in the Save As dialog box and close the dialog box (or let it close automatically when the "Save" button is programmatically "clicked" using VBA).

I've tried using SendKeys but that is inconsistent and partial at best.

My aim is to create a PDF file from the report with the name and location that I control. I want the user to click a button and have everything happen automatically. I don't want the user to select the printer or create the file name or type. I would think this is relatively simple, but it has eluded me for days. Is there anyone who can help especially with specific code samples?

By the way, I've read of doing API calls but have not done that before and from what I've read, it seems like a lot of unnecessary code for something simple. Maybe I'm wrong, but isn't there a simpler solution?

I would really appreciate any help! Thanks in advance!
 
So, the real issue is not how to control the Save As dislog box; the real issue is how to output the report to a PDF with a predetermined filename, without being prompted for the filename?

You may wish to check out the ReportToPDF solution created by Stephen Lebans:
 
Thanks ByteMyzer!
Well, yes and no. I'm aware of Lebans solution, but have not investigated it much. In my case, I may need to use a certain software to create the PDF file. (I may even eventually have/try to use Adobe PDF to create the PDF file.) I may be wrong, but I don't think Lebans' solution gives me that flexibility. Perhaps you know better. Is Lebans' solution the easiest way to accomplish my goal if it doesn't matter how the PDF is created? I would still like to know how to control the Save As dialog box values typically input by the user. Can you help with that? Thanks again!
 
If you are aware of the solution by Steven Lebans, ReportToPDF, you should also be aware that creating a PDF from a report is EXACTLY what it is FOR. With his solution, the following statement:
Code:
ConvertReportToPDF "MyReport", , _
    "C:\MyFolder\MyReport.pdf", _
    False, _
    False
...will generate a PDF file at C:\MyFolder\MyReport.pdf from a report named MyReport, with no Save As dialog box.

Rather than asking ME questions about ReportToPDF, try clicking on the link I provided. You will find all the information that you need.
 
Thanks ByteMyzer,
So far I'm using Lebans solution. I was away for a bit. Haven't had a chance to check into controlling just the SAVE AS dialog, though Lebans' solution may include that. Didn't mean to annoy you with my questions. You're right, I should do more investigation before asking. Thanks, again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top