Using VBA to set the Save As Dialog box text box values

E

Eutychus

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. 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!
 
G

Graham Mandeno

Hi Eutychus

You can certainly do this if you have contro9l of the Save As dialog, but it
sounds like this dialog is controlled by the PDF application.

I suggest you contact the software vendors to ask if there is a way to
control these defaults through code.

Alternatively, you could try Stephen Lebans' solution:
http://www.lebans.com/reporttopdf.htm

It's easy and free!
 
E

Eutychus via AccessMonster.com

Thanks Graham,
I had run across Lebans' code and downloaded it. I was hoping for something
simpler and have not tried to implement the code (at least, yet). I'd still
like to know how to use VBA to set the values in the "Save In," "File name,"
and "File Type" fields on the Save As dialog box. Can you help?
Thanks, again!

Graham said:
Hi Eutychus

You can certainly do this if you have contro9l of the Save As dialog, but it
sounds like this dialog is controlled by the PDF application.

I suggest you contact the software vendors to ask if there is a way to
control these defaults through code.

Alternatively, you could try Stephen Lebans' solution:
http://www.lebans.com/reporttopdf.htm

It's easy and free!
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
[quoted text clipped - 33 lines]
I would really appreciate any help! Thanks in advance!
 
G

Graham Mandeno

Hi Eutychus

Yes, certainly you can set the parameters for the Save As dialog box, BUT
ONLY IF YOU INVOKE THE DIALOG YOURSELF.

You can find out how to do it here:
http://www.mvps.org/access/api/api0001.htm

In your case though, the dialog is being invoked by some other code outside
your control - namely the Virtual PDF application. There may be some way to
tell Virtual PDF what the output file is so that it does not give you a Save
As box. If so, then you can invoke your own Save As to get the file name
and then pass it to Virtual PDF.

I cannot tell you if this is possible or not. The support page for Virtual
PDF (http://www.go2pdf.com/support.html) is not very helpful - it only gives
an email address which you could try if you wish.

I strongly suggest you use Stephen Lebans' method. You will still need to
call your own Save As dialog to get the filename.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Eutychus via AccessMonster.com said:
Thanks Graham,
I had run across Lebans' code and downloaded it. I was hoping for
something
simpler and have not tried to implement the code (at least, yet). I'd
still
like to know how to use VBA to set the values in the "Save In," "File
name,"
and "File Type" fields on the Save As dialog box. Can you help?
Thanks, again!

Graham said:
Hi Eutychus

You can certainly do this if you have contro9l of the Save As dialog, but
it
sounds like this dialog is controlled by the PDF application.

I suggest you contact the software vendors to ask if there is a way to
control these defaults through code.

Alternatively, you could try Stephen Lebans' solution:
http://www.lebans.com/reporttopdf.htm

It's easy and free!
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
[quoted text clipped - 33 lines]
I would really appreciate any help! Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top