Need to set registry keys programatically in Access

Hello Experts;

I am trying to do some automatic PDFing in access, and have this to go on;

However, that code doesn't work in my Access Database.

Can anyone show me the right code to do it within Access?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
First, you need to set a reference to Word in menu Tools, References.

Then, the registry functions must be declared in your code module.
Browse here to the comment from "James":

OzoneFriendlyAuthor Commented:
Sorry, I should have been more specific;

I don't want to use word; What I want to do is have the program automatically create a PDF copy of a report I have created in Access.

I have all the code necessary to find the right data and open the report, and I should be able to change that code to print instead of open the report;

I just need to be able to set a couple of registry keys so that the PDF software will automatically save the PDF where I want with the name I want.

I'll have a look at your link though and see what I can learn there.
Gustav BrockCIOCommented:
If so, install a pdf printer like this (free, uses Apple Postscript and Ghostscipt and comes with a multi lingual UI):

and select that as your default printer or set the report to use that printer.

Another method is to use snapshot files and the code from Lebans:

Also, search the archive here for writing/printing to pdf. Numerous suggestions exist.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Do you have the CutePDF Writer with Programattic Access? If not, those reg keys won't do you any good. I have this utility and it works very well, but it's pricey. The Lebans method mentioned by gustav might do fine for you.

Here's a post with a module that allows registry modifications; see the last posting for the code:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OzoneFriendlyAuthor Commented:
Hello experts;

Thanks for your suggestions; I have purchased the CutePDF solution, so now I just need to figure out the registry key setting code, and I should be all good. I'l look into LSMConsulting's suggestions now and see what I come up with.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If you have the CutePDF with Programatic Acces, then you can use the code shown in your earlier code. Note that you must also have a converter:

PDF writer requires PS2PDF converter such as GPL Ghostscript (recommended).

The utility used to ship with this converter, but it's a separate download now.
OzoneFriendlyAuthor Commented:
Thanks LSMConsulting!

The answer to my question was certainly not a one line paragraph as I had hoped, but your pointers got me on the right track.

With the help of these questions;

I found this link;

And used that stuff to make it work.  I incorporated the .bas file as a module in my access database, and could then use this code to set the registry keys;

regCreate_A_Key HKEY_CURRENT_USER, "Software\PDF Creator"
regCreate_Key_Value HKEY_CURRENT_USER, "Software\PDF Creator", "Outputfile", "c:\poles\inv.pdf"
regCreate_A_Key HKEY_CURRENT_USER, "Software\PDF Creator"
regCreate_Key_Value HKEY_CURRENT_USER, "Software\PDF Creator", "BypassSaveAs", "1"

I had to make one minor change to the .bas code I got, as it was setting up the registry value as a DWORD if the data was numeric; CutePDF wants on REG_SZ. So I just made it always create REG_SZ, which is fine for this application.

Sensational. :-)

Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.