Print To PDF - Almost There....

Nov 9, 2005

The code below does not give me any error. I do get a file save dialog box and i put the file name and a message saying export is done. but in reality there is no pdf file saved under what ever directory i told the system to save...




Public Sub Print2PDF(strReportName As String, Optional strPath As String)

Dim stDocName As String, strFilter As String
Dim Distiller As ACRODISTXLib.PdfDistiller

'InputPSFile - path to existing PS file in c: emp
'OutputPDFFile - path of PDF file to be created in c: emp
'2 lines of code:
'ACRODISTXLib.PdfDistillerClass Distiller=new ACRODISTXLib.PdfDistillerClass();
'Distiller.FileToPDF(InputPSFile, OutputPDFFile,"");

Set Distiller = CreateObject("PdfDistiller.PdfDistiller.1")
Distiller.bSpoolJobs = False
Distiller.bShowWindow = False
ITransform_Transform = False

'Ask for the path if it is not provided
If Trim(strPath) = "" Then
strFilter = ahtAddFilterItem(strFilter, "Adobe PDF Files (*.pdf)", "*.pdf")
strPath = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
End If

'If Distiller.FileToPDF(pFromFile, pToFile, "") Then

'If Distiller.FileToPDF("strReportName.ps", "", "") Then
Distiller.FileToPDF "strReportName.ps", "", ""

'Distiller.FileToPDF OutputDir & "" & ps, OutputDir & "" & pdf, ""
' ITransform_Transform = True
'End If

Set Distiller = Nothing

End Sub

View Replies


ADVERTISEMENT

I Want To Print A Report And Programmatically Set The Printer Name And 'Print To File

Jul 16, 2007

How can I print a report and at the same time programatically set the printer name and 'Print to File' option and set the path of this option?

View 1 Replies View Related

How To Hide Or Disable Print Or Quick Print Options

Dec 4, 2014

I have a form which my company wanted that each single record should be printed from form. I made a print record button and put code to print single page or record. However as a natural habit people go to file > print to print which leads printing all records so 1000's records start printing. Is there any way i can hide print button. File >Print button.

View 1 Replies View Related

Reports :: Unbound Report - Print Preview OK But None Of Fields Print When Report Directly Send To Printer

May 25, 2013

I have an unbound form with an associated report. When the user hits the 'print' button on the form/screen, the report is launched in the background. In the On Load event of the report I populate the report fields from the forms field as so:

Code:
Me.txtAddrMainLine2 = "NAME " & UCase([Forms]![frm_OrderRx].[txtPatientName])

This works like a charm as long as I call the report in Print Preview mode (i.e. with acViewPreview). But if I send the report directly to the printer, none of the fields print.

I've read about using other report events to populate the fields (e.g., On Format and On Print) and also something about using TempVars to pass the data. But I haven't read anything that's clear and definitive about the full answer.

View 3 Replies View Related

Print To PDF

Nov 10, 2005

I used to be able to create PDFs, automatically save them to a file,
and mail them out to people. This was on Access 97 with Windows NT.
We've changed to Windows XP and Access 2003. Doesn't work anymore.
Part of the problem is that the users have no access to the registry
and can only save files on the C: drive to their My Documents folder.
I found this code on the web, but it doesn't work either. The files
continue to print out of my printer instead of making a PDF. I put the
entire code at the bottom, but here is the part I'm calling:

Public Sub SaveReportAsPDF(strReportName As String, Optional strPath As String)

Dim strOldDefault As String
Dim strFilter As String

'Ask for the path if it is not provided
If Trim(strPath) = "" Then
strFilter = ahtAddFilterItem(strFilter, "Adobe PDF Files (*.pdf)", "*.pdf")
strPath = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
End If

'remember old printer
strOldDefault = QueryKey("SoftwareMicrosoftWindowsCurrentVersionWindows", "Device")

'changes to pdf writer
SetKeyValue "SoftwareMicrosoftWindowsCurrentVersionWindows", "Device", "Adobe PDF", REG_SZ

SetKeyValue "SoftwareAdobeAcrobat Distiller", "PDFFilename", strPath, REG_SZ

SetKeyValue "SoftwareAdobeAcrobat Distiller", "bExecViewer", 0, REG_SZ

'Distiller.FileToPDF strReportName
DoCmd.OpenReport strReportName

'put the old printer back to default
SetKeyValue "SoftwareMicrosoftWindowsCurrentVersionWindows", "Device", strOldDefault, REG_SZ

End Sub



The entire code:

' ################################################## #######
Option Compare Database
Option Explicit

Public Const REG_SZ As Long = 1
Public Const REG_DWORD As Long = 4

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003

Public Const ERROR_NONE = 0
Public Const ERROR_BADDB = 1
Public Const ERROR_BADKEY = 2
Public Const ERROR_CANTOPEN = 3
Public Const ERROR_CANTREAD = 4
Public Const ERROR_CANTWRITE = 5
Public Const ERROR_OUTOFMEMORY = 6
Public Const ERROR_ARENA_TRASHED = 7
Public Const ERROR_ACCESS_DENIED = 8
Public Const ERROR_INVALID_PARAMETERS = 87
Public Const ERROR_NO_MORE_ITEMS = 259

Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_ALL_ACCESS = &H3F

Public Const REG_OPTION_NON_VOLATILE = 0

Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
"RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
As Long, phkResult As Long, lpdwDisposition As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
Long) As Long
Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
As String, lpcbData As Long) As Long
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, lpData As _
Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
As Long, lpcbData As Long) As Long
Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
String, ByVal cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
ByVal cbData As Long) As Long
Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
lType As Long, vValue As Variant) As Long
Dim lValue As Long
Dim sValue As String
Select Case lType
Case REG_SZ
sValue = vValue & Chr$(0)
SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
lType, sValue, Len(sValue))
Case REG_DWORD
lValue = vValue
SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
lType, lValue, 4)
End Select
End Function
Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
String, vValue As Variant) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String

On Error GoTo QueryValueExError

' Determine the size and type of data to be read
lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
If lrc <> ERROR_NONE Then Error 5

Select Case lType
' For strings
Case REG_SZ:
sValue = String(cch, 0)

lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _
sValue, cch)
If lrc = ERROR_NONE Then
vValue = Left$(sValue, cch - 1)
Else
vValue = Empty
End If
' For DWORDS
Case REG_DWORD:
lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, _
lValue, cch)
If lrc = ERROR_NONE Then vValue = lValue
Case Else
'all other data types not supported
lrc = -1
End Select

QueryValueExExit:
QueryValueEx = lrc
Exit Function

QueryValueExError:
Resume QueryValueExExit
End Function
Public Function CreateNewKey(sNewKeyName As String, lPredefinedKey As Long)

Dim hNewKey As Long ' Handle to the new key
Dim lRetVal As Long ' Result of the RegCreateKeyEx function

lRetVal = RegCreateKeyEx(lPredefinedKey, sNewKeyName, 0&, vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, 0&, hNewKey, lRetVal)

RegCloseKey (hNewKey)

End Function
Public Function SetKeyValue(sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)

Dim lRetVal As Long ' Result of the SetValueEx function
Dim hKey As Long ' Handle of open key

' Open the specified key
lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, KEY_SET_VALUE, hKey)

lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)

RegCloseKey (hKey)

End Function
Public Function QueryKey(sKeyName As String, sValueName As String)

Dim lRetVal As Long ' Result of the API functions
Dim hKey As Long ' Handle of opened key
Dim vValue As Variant ' Setting of queried value

lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, KEY_QUERY_VALUE, hKey)

lRetVal = QueryValueEx(hKey, sValueName, vValue)

QueryKey = vValue

RegCloseKey (hKey)

End Function
Public Sub SaveReportAsPDF(strReportName As String, Optional strPath As String)

Dim strOldDefault As String
Dim strFilter As String

'Ask for the path if it is not provided
If Trim(strPath) = "" Then
strFilter = ahtAddFilterItem(strFilter, "Adobe PDF Files (*.pdf)", "*.pdf")
strPath = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)
End If

'remember old printer
strOldDefault = QueryKey("SoftwareMicrosoftWindowsCurrentVersionWindows", "Device")

'changes to pdf writer
SetKeyValue "SoftwareMicrosoftWindowsCurrentVersionWindows", "Device", "Adobe PDF", REG_SZ

SetKeyValue "SoftwareAdobeAcrobat Distiller", "PDFFilename", strPath, REG_SZ

SetKeyValue "SoftwareAdobeAcrobat Distiller", "bExecViewer", 0, REG_SZ

'Distiller.FileToPDF strReportName
DoCmd.OpenReport strReportName

'put the old printer back to default
SetKeyValue "SoftwareMicrosoftWindowsCurrentVersionWindows", "Device", strOldDefault, REG_SZ

End Sub

View 1 Replies View Related

Print Subdatasheet

Nov 24, 2005

Hi!

I would like to print a table including subdatasheets in Access. However, in Access 2002 it collapses them, and closes the table when I click on Print Preview. (In Access 2000 it works.)
Any ideas?

View 1 Replies View Related

Print Form, HELP!

Mar 31, 2006

Hello!

I would like to be able to print a specified form when a new record is added to my database.

I have an add form which can be filled in, and there is an "Add" button at the bottom of the page, when this is clicked, I want the record to be added but also a specified form to be printed named "frmKitChecklist".

As I am a VB noob I do not know the code to do this, please could someone help me!

Thanks :)

View 3 Replies View Related

Print Problem

Aug 16, 2006

I have the following problem:The print button in access was associated with the default printer, but for some reason know there is no printer associated with it. If I click on it nothing happens. Also if i go through File->Print no screen pops up. Can anyone help me with this problem.TIA,Roda

View 3 Replies View Related

Print Tables

Sep 18, 2006

Hi,

Is there anyway to print tables when they are in design view?
I can't even copy and paste it on spread sheet!

Regards,
B

View 5 Replies View Related

How Do I Print On Envelopes?

Jan 2, 2007

I have 3 tables of Adds in my DB...
I have 3 dif. env.s (ranging in dimensions)
I want to able to choose the adds i want to print out on selective env.s And print them out... how do i get to do it?

View 2 Replies View Related

Print VBA Code

Apr 5, 2007

I need to print out my VBA code , I was wondering if there is an easier way to do it without cutting and pasting it onto Microsoft word.

View 1 Replies View Related

Code To Print!

Aug 24, 2007

Hello,

What's is the exact syntax to print a subformB (within a formA) using VBA code?
The code will be on the OnClick event of a button and the button is on formA.

Thanks

View 1 Replies View Related

Print Marker

Jan 28, 2008

I need a system which will tick all the boxes to corresponding records when I print a report?
The next time I open the report it would only show the unticked boxes which had yet to be printed.

Thanks for your help,

Richard

View 3 Replies View Related

Print Out With Fieldnames

Feb 11, 2005

Is there an easy way to printout a form in disignview so the fieldnames appear in the inputboxes? I've a form with 11 tabs and on each tab at least 10 input boxes (10x11 = 110 boxes :eek: ) Writing down the names on a printout is NOT effective

Thnx

View 2 Replies View Related

Print Options

Feb 17, 2005

I ned to create a form that asks the user which reports they want to preview/print. I see it as a set of tick boxes with one saying all, then a print button. Im not really sure though, can someone offer some advise or maybe an example?

View 5 Replies View Related

Fields Won't Print

Mar 16, 2005

Hi, (sorry to be cross-posting, but I didn't get any response from Modules and VBA)
I've messed something up, I think. But I'm not sure if I messed up VB or some connection in Access.

The Symptoms: I've got a print page with checkboxes that represent other form pages in my db.
The page basically prints ok, except where field information is supposed to be.
Wherever there should be field info, it prints #Name? instead. Each field can't seem to find it's info.

The funny thing is that the information displays correctly in the form onscreen.
Just not when I print.
Basically someone else wrote the the Print code and I've been hacking away to make this code work for 3 new forms (e.g. 3 new checkboxes).
While I'm not terribly familiar with VB, I know my way around script and I'm pretty sure I haven't really messed up that code.

How I got there:
At one point in my building of this thing, every time I went to open the 'print' page, I would get an error and drop into VB.
Well, this was driving me nuts, and at that point I hadn't altered the code. I was just trying to view the print page. So, I cleverly pasted into VB the code from an earlier version of the db. This cleared up the debug error nicely, and I was able to finish the code that would allow me to choose 3 new pages to print. But now it's doing the symptom above.

Any help would be appreciated.
Scott

View 3 Replies View Related

Print Report To PDF

Apr 28, 2005

Hey Guys,

I have searched and searched for this on the forum but to no avail. :(

I have just installed Adobe Acrobat 6.0 and so can create PDFs. Does anyone know the code I need for a button on a form to print a report to PDF format?

Many thanks,

Rusty
:D

View 4 Replies View Related

Pop-Up Print Button

May 4, 2005

First I should say that this is my first post, and I'm very new to this. Now on to my problem. We have a form with a bunch (like 25) of buttons that are links to specific reports. When you click on one of the buttons the report opens up along with a little pop up form with a print button on it. How can I get this print button to print the report that is open? Do I have to put in code for every possible report that may be open, or can I just say "print the current report" somehow?

Thanks,

Nick Jones

View 5 Replies View Related

Print Current

Jun 23, 2005

I have a control on a form where a user inputs a number then presses enter. The AfterUpdate event prints a report. The problem is that it prints the previous record each time its updated. I want to print the current record. Maybe some type of requery before the event happens. Any ideas?

View 1 Replies View Related

Print Pageheader

Jul 7, 2005

Hi All,

How can I write a code where a form only prints the PageHeader and not the Formheader (don't know how you call it in english)

View 1 Replies View Related

Print Only First Page

Aug 17, 2005

I have a form... everything looks good. Sometimes it pulls 5 records, sometimes only 2....

Is there a way to only print the first result no matter what. Whenever there is an extra couple results I do not want those to print.

View 1 Replies View Related

Print From Form Vol. 2

Oct 4, 2005

I got the command buttons to print the reports I wanted from the forms.
I now have a data entry form (data entry = yes). I would like to print a report from this form. All I get are blank fields. I think it may be a problem in the Where condition on the Open Report function.

I am using:
[Forms]![complaintentryform]

The completed form contains all data I want on the report.
I have tried printing it from the table, but I get blank fields there as well.

All suggestions cheerfully received.

View 4 Replies View Related

Print Wizard Help

Nov 4, 2005

Print Wizard Help (http://www.access-programmers.co.uk/forums/showthread.php?t=96689)

View 1 Replies View Related

Table Print

Jun 7, 2006

I have a print button on my form that prints inputs stored in a table. I saved my print setting so that all the columns fit into 1 page but when I go to print from my form it prints to two pages.

Is there any way to fix this????

View 2 Replies View Related

Print Then Update

Oct 5, 2004

I am looking at a way that I can print a report then update a field called printed to "True". I've used the wizard to get the following code to print the report - can I just add a line before the ExitSub to update the "printed" field? If yes, can someone give me some code to start?


Private Sub prntreport_Click()
On Error GoTo Err_prntreport_Click
Dim stDocName As String

stDocName = "BCT Offer Generation Request"
DoCmd.OpenReport stDocName, acNormal

Exit_prntreport_Click:
Exit Sub

Err_prntreport_Click:
MsgBox Err.Description
Resume Exit_prntreport_Click

End Sub

thanks for all your help.

View 4 Replies View Related

I Want To Print In Batches

Dec 31, 2004

I have a tblClient with about 700 records.
I want to be a able press a button and the first 50 records print and then have a second button that will print the next 50 records so on until all the records are done.

Now the problem is i dont know how to pick each batch of records on its own, and second the client database is always growing so i dont want to have to always add a button that will print the next set of records, also in this situation i would like to have a note for each buttoon saying when it was last cliked so i wont print out the same batch twice.

Now i figure the best solution would be run a a code that will print the first 50 records prompt me to cotinue or to stop. if the stop button is clicked it should register at how many loops it is at so on the next time it runs it skips that amount of loops.
Again im not sure how to pick the records or in this case how to retain the loop info.
Thank you
Mark

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved