Running adobe from Access

  • Thread starter Thread starter AMC
  • Start date Start date
A

AMC

Hi,

I want to have a button on a form that will run Adobe Acrobat and a open a
specific file whose name I would like to specify in code.
Does anyone know how to do this?

THanks,
AC
 
Hi,

Use something like

Application.FollowHyperlink "D:\folder\folder\filename.pdf"

in the button's Click event procedure.
 
Not sure if this will help:

Why don't you set the file name in the INI file? You could set the file
name just prior to making the print call, and then set it back to a default,
(if necessary), when you're through.

You can use the GetPrivateProfileString and WritePrivateProfileString API
calls to query and edit the pdfwritr.ini file. The declarations for the API
calls can be obtained from the WinAPI Viewer AddIn.

The two key parameters for each call and the values you should pass are:

ApplicationName = "Acrobat PDFWriter"
KeyName = "PDFFileName"

Your other solution of copying INI files around will work, but actually
setting the value in the INI file is a bit cleaner and eliminates the
potential problems with file contention, (won't let you copy the file
because it is already in use by another process.)



JL said:
I have found a way around the annoying prompt that Acrobat Writer puts up
even when you are trying to output a report programmatically. There is an
Acrobat INI file called PDFWritr.ini which can be found in the Windows
System subdirectory.

You can edit this file in Notepad/WordPad. All you need to do is enter a
value for the PDFFileName= argument and this will suppress the dialog box
from appearing.

[Acrobat PDFWriter]
CreatePDFExcelMacroShowDialog=Prompt
PDFFileName="MyPDF.pdf"

The bad Whenever you decide to print to PDF, this is the file name
that will be used. I have written some code which renames several
PDFWritr.ini files I have staged in my Windows System subdirectory. Once my
program finishes, it swaps back to the default PDFWritr.ini file which
prompts for a file name.

--JL


cath grainger said:
Is there anyway to stop the confirmation boxes "Save PDF file as" and
"Acrobat Writer Document Information" from appearing when printing to PDF
printer ?


Here is one solution:

Function AdobePDF accepts two arguments, the first (lpString) is
the path/filename for the output PDF file (e.g. "c:\mypdf.pdf") and the
second (ReportName) is the reportname in the currently open database (e.g.
"MyReport"). When running the function from the immediate window or a macro
with the supplied arguments, it creates the PDF file.
-----------------------

Option Compare Database

Declare Function WritePrivateProfileString Lib "kernel32" Alias
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal
lpKeyName As Any, ByVal lpString As Any, ByVal lpFilename As String) As Long

Function AdobePDF(lpString As String, ReportName)
Call WritePrivateProfileString("Acrobat PDFWriter", "PDFFilename",
lpString, "c:\windows\system\pdfwritr.ini")
DoCmd.OpenReport ReportName, acViewNormal, "", "", acNormal
End Function

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

The one caveat is that (ReportName) must be saved with the printer as "Adobe
PDFWriter".


The PDF file has descriptions of the different keys that you can edit for
PDFWriter
Here is the code that will edit the registry, Careful with the line wraps.

Examples:
Dim lngRetVal as Long
lngRetVal = SetRegValue("HKEY_CURRENT_USER", "Software\Adobe\Acrobat
PDFWriter", "PDFFileName", "C:\Temp\YourFile.pdf")
lngRetVal = SetRegValue("HKEY_CURRENT_USER", "Software\Adobe\Acrobat
PDFWriter", "bExecViewer", "0")
lngRetVal = SetRegValue("HKEY_CURRENT_USER", "Software\Adobe\Acrobat
PDFWriter", "bDocInfo", "0")

'------------------------------------START----------------------------------
-------
Option Compare Database
Option Explicit

Declare Function RegOpenKeyA Lib "advapi32.dll" (ByVal hKey As Long, ByVal
sSubKey As String, ByRef hkeyResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegSetValueExA Lib "advapi32.dll" (ByVal hKey As Long,
ByVal sValueName As String, ByVal dwReserved As Long, ByVal dwType As Long,
ByVal sValue As String, ByVal dwSize As Long) As Long
Declare Function RegCreateKeyA Lib "advapi32.dll" (ByVal hKey As Long, ByVal
sSubKey As String, ByRef hkeyResult As Long) As Long
Declare Function RegQueryValueExA Lib "advapi32.dll" (ByVal hKey As Long,
ByVal sValueName As String, ByVal dwReserved As Long, ByRef lValueType As
Long, ByVal sValue As String, ByRef lResultLen As Long) As Long
Declare Function RegDeleteKeyA Lib "advapi32.dll" (ByVal hKey As Long, ByVal
lpSubKey As String) As Long
Declare Function RegDeleteValueA Lib "advapi32.dll" (ByVal hKey As Long,
ByVal lpValueName As String) As Long

Function GetRegValue(ByVal key As String, ByVal Path As String, ByVal
ValueName As String, ByVal Default As String) As String
'Get text value from registry
'eg: Debug.Print GetRegValue("HKEY_LOCAL_MACHINE", "Network\Logon",
"UserName", "Stuart")
On Error GoTo Proc_Error
Dim hKey As Long
Dim lngValueType As Long
Dim strResult As String
Dim lngResultLen As Long
Dim X As Long
Dim lngThisKey As Long

Select Case UCase(key)
Case "HKEY_CLASSES_ROOT": lngThisKey = &H80000000
Case "HKEY_CURRENT_USER": lngThisKey = &H80000001
Case "HKEY_LOCAL_MACHINE": lngThisKey = &H80000002
Case "HKEY_USERS": lngThisKey = &H80000003
Case "HKEY_CURRENT_CONFIG": lngThisKey = &H80000004
Case "HKEY_DYN_DATA": lngThisKey = &H80000005
End Select
If lngThisKey = 0 Then
Err.Raise vbObjectError + 1, , "Root key: " & key & " not found."
End If

If RegOpenKeyA(lngThisKey, Path, hKey) <> 0 Then
'Create key if not found
RegCreateKeyA lngThisKey, Path, hKey
End If

lngResultLen = 255: strResult = Space(lngResultLen)
X = RegQueryValueExA(hKey, ValueName, 0&, lngValueType, strResult,
lngResultLen)
If X = 0 Then
GetRegValue = left(strResult, lngResultLen - 1)
Else
GetRegValue = Default
'Return default and create value if not found
SetRegValue key, Path, ValueName, Default
End If

Proc_Exit:
RegCloseKey hKey
Exit Function
Proc_Error:
MsgBox Err.Description, vbCritical
Resume Proc_Exit
End Function

Function SetRegValue(ByVal key As String, ByVal Path As String, ByVal entry
As String, ByVal Value As String) As Boolean
'Set text value in registry
'eg: SetRegValue "HKEY_LOCAL_MACHINE", "Network\Logon", "UserName", "Stuart"
On Error GoTo Proc_Error
Dim hKey As Long
Dim lngThisKey As Long

Select Case UCase(key)
Case "HKEY_CLASSES_ROOT": lngThisKey = &H80000000
Case "HKEY_CURRENT_USER": lngThisKey = &H80000001
Case "HKEY_LOCAL_MACHINE": lngThisKey = &H80000002
Case "HKEY_USERS": lngThisKey = &H80000003
Case "HKEY_CURRENT_CONFIG": lngThisKey = &H80000004
Case "HKEY_DYN_DATA": lngThisKey = &H80000005
End Select

If lngThisKey = 0 Then
Err.Raise vbObjectError + 1, , "Root key: " & key & " not found."
End If
If RegOpenKeyA(lngThisKey, Path, hKey) <> 0 Then
RegCreateKeyA lngThisKey, Path, hKey
End If
SetRegValue = (RegSetValueExA(hKey, entry, 0&, 1&, Value, Len(Value) +
1) = 0)
Proc_Exit:
RegCloseKey hKey
Exit Function
Proc_Error:
MsgBox Err.Description, vbCritical
Resume Proc_Exit
End Function
'------------------------------------END------------------------------------
 
Thanks,

That worked great.

Ac
John Nurick said:
Hi,

Use something like

Application.FollowHyperlink "D:\folder\folder\filename.pdf"

in the button's Click event procedure.
 
Back
Top