Interfacing to Adobe

T

Tony Epton

Win XP, Access 2003, Adobe 6.0 Professional

I am attempting to switch a report between the default printer and an
Adobe driver. (switching at user discretion via a tick box call ChkPDF
- logic not shown in code below)

ISSUE 1
-------------
I have done some reading about prtDevMode and this is the code I have
tried so far:

Private Type str_DEVMODE
RGB As String * 94
End Type

Private Type type_DEVMODE
strDeviceName As String * 32
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 32
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type

Sub PatchReportPrinter()


Dim rpt As Report
Dim DevString As str_DEVMODE
Dim DM As type_DEVMODE
Dim strDevModeExtra As String

DoCmd.OpenReport "rptGraph", acViewDesign
Set rpt = Reports![rptGraph]
strDevModeExtra = rpt.PrtDevMode

' Gets current DEVMODE structure.
DevString.RGB = strDevModeExtra
LSet DM = DevString


MsgBox DM.strDeviceName

end sub


If I leave the report design set to the default printer and run this
code, the message box line above gives a blank response (could be 32
spaces - have not checked yet).

When I hand code the report design to go to a specific printer "Adobe"
and then run the code then the message box line above yields "????F"
which is not what I am expecting.

I must be doing something wrong already - so don't want to go any
further with the code where I alter the DeviceName and stuff it back
in to rpt.DevMode

Any suggestion please - much appreciated.

ISSUE 2
-------------
If I circumvent this code and just hard code the report to go to adobe
- then adobe generates a file : My Documents\rptGraph.pdf

I would like to grab this file and copy it to another location (and
another name)

Here is my code so far

sub CopyPDFToNamedFile(strOutputFileName as string)

DoCmd.OpenReport "rptGraph", acViewNormal
'Arbitary delay because we don't know when Adobe has finished
For i = 1 To 1000
DoEvents
Next i

strUserName = "Administrator"
strMyDocuments = "C:\Documents and Settings\" & strUserName & "\My
Documents"
FileCopy strMyDocuments & "\rptGraph.pdf", strOutputFileName

end sub

As you can see - I have hardcoded the user name.
Can anyone tell me how to pick this name up using some function.
(NOT the access login name)

Many thanks in advance

Tony Epton
 
A

Albert D. Kallal

Two things:

You don't need printDevmode to switch a printer.

In access 2002 and later, there is a built in printer object, and it lets
you switch the printer with ease.

You can use:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName

' switch to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever.

Switch back.

Set Application.Printer = Application.Printers(strDefaultPrinter)

However, you don't even need the above code.

I would suggest you dump the use of adobe, and use Stephens free solution
here:

http://www.lebans.com/reporttopdf.htm

The advantages of the above solution:

** you don't have to switch printers
** you don't even have to install a printer driver
** you can specify the PDF output name in code (no need to copy as you ask)
** it is free
** You don't have to install a big bulky adobe program.

So, #1, you don't need preDev since access 2002 and liters
#2, if you use Stephans solution, you don't even have to CHANGE printers
anyway
 
T

Tony Epton

Two things:

You don't need printDevmode to switch a printer.

In access 2002 and later, there is a built in printer object, and it lets
you switch the printer with ease.

You can use:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName

' switch to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever.

Switch back.

Set Application.Printer = Application.Printers(strDefaultPrinter)

However, you don't even need the above code.

I would suggest you dump the use of adobe, and use Stephens free solution
here:

http://www.lebans.com/reporttopdf.htm

The advantages of the above solution:

** you don't have to switch printers
** you don't even have to install a printer driver
** you can specify the PDF output name in code (no need to copy as you ask)
** it is free
** You don't have to install a big bulky adobe program.

So, #1, you don't need preDev since access 2002 and liters
#2, if you use Stephans solution, you don't even have to CHANGE printers
anyway
Many thanks Albert - that was very helpful and very interesting.
The clients already have Adobe Professional and use it against all
sorts of applications they are already running - though I guess there
is nothing to stop me coming up with an application that does not need
it.

I am still really interested in having a solution to the second issue
- many 3rd party applications dump output in to "My Documents" and I
would very much like to be able to get to this directory when doing a
FileCopy

Many thanks
Tony Epton
 
P

Pieter Wijnen

Private Const ERR_SUCCESS = 0
Private Const MAX_PATH = 260

Private Declare Function SHGetSpecialFolderLocation Lib "shell32" (ByVal
hWnd As Long, ByVal nFolder As Long, pidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (pidl As Long,
ByVal Path As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal p As Long)


Public Function GetMyDocuments() As String

Dim Ret As Long
Dim Folder As String
Dim pidl As Long

Ret = SHGetSpecialFolderLocation(Access.Application.hWndAccessApp, &H5,
pidl)
If Ret = ERR_SUCCESS Then
Folder = VBA.String(MAX_PATH, VBA.vbNullChar)
Ret = SHGetPathFromIDList(ByVal pidl, Folder)
If Ret <> 0 Then
GetMyDocuments = VBA.Left(Folder, VBA.InStr(Folder, VBA.vbNullChar) -
1)
End If
CoTaskMemFree pidl
End If
End Function

HtH

Pieter
 

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