Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2006
    Posts
    26

    Question Unanswered: Access97 PDF File Name problem

    I am able to create PDF from Access97 report, but it always ask for file name for it. I want to be able to assign name so that it doesn't popup with output file name browser.

    I've tried setting in Adobe PDF printing defaults for output folder. And tried setting PDFFileName=c:\temp\filename.pdf at registry HKEY_CURRENT_USER->Software->Adobe->Adobe PDF. Also tried several suggestions on net, but non seem to work.

    I found some info for Access2000 and up, but they don't work on Access97. Some directions would be appreciated.

    Below is the latest I've found, but still asks for file/path:
    Code:
    Option Compare Database
    Option Explicit
    
    
    '**************************************
    'Windows API/Global Declarations for Creating PDF from MS Access Report
    '**************************************
    
    Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
    Declare Function RegOpenKeyEx Lib "advapi32" 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 RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal szData As String, ByVal cbData As Long) As Long
    Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
    Declare Function RegCreateKeyEx Lib "advapi32" 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, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
    
        #If Win32 Then
            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 KEY_ALL_ACCESS = &H3F
            Public Const REG_OPTION_NON_VOLATILE = 0&
            Public Const REG_CREATED_NEW_KEY = &H1
            Public Const REG_OPENED_EXISTING_KEY = &H2
            Public Const ERROR_SUCCESS = 0&
            Public Const REG_SZ = (1)
        #End If
    
    Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Boolean
        End Type
    
    '**************************************
    ' Name: Create PDF from MS Access Report
    '
    ' Description:On a machine where the Ado
    '     be PDFWriter is installed, the current p
    '     rinter is swapped out with the PDFWriter
    '     and the PDF file is created. The origina
    '     l printer is then restored.
    ' By: Todd Benson
    '
    ' Inputs:rptName = Microsoft Access repo
    '     rt name you want to create pdf from. sPD
    '     FPath = the directory path where you wan
    '     t to create the pdf file (ex. - "c:\data
    '     \"). sPDFName = the name of the pdf file
    '     you are wanting to create (ex. - "file00
    '     1.pdf").
    '
    ' Assumes:This code is easily modified t
    '     o be used in other programs
    '
    ' Side Effects:Please use the most recen
    '     t installs of Adobe Exchange or PDFWrite
    '     r to ensure proper functionality.
    '
    'This code is copyrighted and has' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=35321&lngWId=1'for details.'**************************************
    
    Public Function bGetRegValue(ByVal hKey As Long, ByVal sKey As String, ByVal sSubKey As String) As String
    
        Dim lResult As Long
        Dim phkResult As Long
        Dim dWReserved As Long
        Dim szBuffer As String
        Dim lBuffSize As Long
        Dim szBuffer2 As String
        Dim lBuffSize2 As Long
        Dim lIndex As Long
        Dim lType As Long
        Dim sCompKey As String
        Dim bFound As Boolean
        lIndex = 0
        lResult = RegOpenKeyEx(hKey, sKey, 0, 1, phkResult)
    
        Do While lResult = ERROR_SUCCESS And Not (bFound)
            szBuffer = Space(255)
            lBuffSize = Len(szBuffer)
            szBuffer2 = Space(255)
            lBuffSize2 = Len(szBuffer2)
            lResult = RegEnumValue(phkResult, lIndex, szBuffer, lBuffSize, dWReserved, lType, szBuffer2, lBuffSize2)
    
            If (lResult = ERROR_SUCCESS) Then
                sCompKey = Left(szBuffer, lBuffSize)
    
                If (sCompKey = sSubKey) Then
                    bGetRegValue = Left(szBuffer2, lBuffSize2 - 1)
                    RegCloseKey phkResult
                    Exit Function
                End If
    
            End If
    
            lIndex = lIndex + 1
        Loop
    
        RegCloseKey phkResult
    End Function
    
    Public Function bSetRegValue(ByVal hKey As Long, ByVal lpszSubKey As String, ByVal sSetValue As String, ByVal sValue As String) As Boolean
    
        On Error Resume Next
        Dim phkResult As Long
        Dim lResult As Long
        Dim SA As SECURITY_ATTRIBUTES
        Dim lCreate As Long
        RegCreateKeyEx hKey, lpszSubKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, phkResult, lCreate
        lResult = RegSetValueEx(phkResult, sSetValue, 0, REG_SZ, sValue, CLng(Len(sValue) + 1))
        RegCloseKey phkResult
        bSetRegValue = (lResult = ERROR_SUCCESS)
    End Function
        
    'rptName = Microsoft Access report name you want to create pdf from
    'sPDFPath = the directory path where you want to create the pdf file (ex. - "c:\data\")
    'sPDFName = the name of the pdf file you are wanting to create (ex. - "file001.pdf")
    '
    Public Function RunReportAsPDF(rptName As String, rptFilter As String, sPDFPath As String, sPDFName As String)
    
        Dim sMyDefPrinter As String
        On Error GoTo Err_RunReport
        'Save current default printer
        sMyDefPrinter = bGetRegValue(HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device")
        ' Set default printer to PDF Writer
        bSetRegValue HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", "Adobe PDF"
        'Setting value for PDFFileName in the registry stops file dialog box from appearing
        bSetRegValue HKEY_CURRENT_USER, "Software\Adobe\Adobe PDF", "PDFFileName", sPDFPath + sPDFName
        'Run the report
    
    
        DoCmd.OpenReport rptName, acViewNormal, , rptFilter
    Exit_RunReport:
            ' Restore default printer
            bSetRegValue HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device", sMyDefPrinter
            Exit Function
    Err_RunReport:
            MsgBox Err.Description
            Resume Exit_RunReport
    End Function
    
    ' Test
    Function testPDF()
        RunReportAsPDF "Invoices No Passwords", "[ID]=73961", "c:\temp\", "testPDF.pdf"
    
    End Function

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Yep. PDF coding is a PAIN (I mean a BIG pain). If you're using the Adobe PDF driver (or some other PDF driver), your basically re-directing the printing to a file which prompts for the file name. You "may" be able to code in something to automate sending the file name but since I detest Adobe and PDF and always had problems using the driver, I gave up and instead use something like CutePDF.

    Sorry - I don't have any suggestions. I can tell you I spent many, many days trying to get it to automatically send the filename automatically but always got the Adobe prompt to save the filename. (did I say I hate Adobe?) Nothing like a piece of software which ALWAYS embeds itself into your startup every time you use it. Same as Quicktime.

    I don't like things that automatically (and SILENTLY) install themselves into my startup and services.msc ANYTIME I use their service!! To me - that's a virus!! If I open a pdf document or Quicktime document, I then have to edit msconfig and uncheck the damn thing so it doesn't automatically start on startup!!

    You can try looking at this: http://www.dbforums.com/6436150-post95.html (ie. code bank) and http://www.dbforums.com/microsoft-ac...de-bank-7.html

    which may or may not be helpful - it has coding for pdf creation and will hopefully help.
    Last edited by pkstormy; 01-23-10 at 20:25.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Feb 2006
    Posts
    26
    Thanks for the link. I tried and it somewhat works...

    When it reaches the StrStorage function ConvertUncompressedSnapshot, it creates the *.tmp file then causes system errors "Microsoft Access has encountered a problem and needs to close." Once the error is closed and access shut down, it creates the correct *.pdf file.

    One thing I did noticed the file versions:

    dynapdf.dll v2.0.43.425 dated Jan 15, 2009 size .96MB
    StrStorage.dll no version dated Feb 02, 2009 size 88KB

    These files were downloaded directly from Lebans.com. I've also downloaded older version released on Jun 9, 2008. Is there another version of StrStorage.dll?
    Last edited by itchibahn; 01-24-10 at 21:46.
    We're just a speck of dust in a universe.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I couldn't say for sure regarding the version. It's been a long time since I worked with creating pdfs (the code I posted in the code bank was code I dug up from my archives.) Sorry but I can't help you much on this but hopefully someone else can respond. If not, try posting under a new thread.

    This error
    "Microsoft Access has encountered a problem and needs to close."

    doesn't sound like the pdf problem (but I could be wrong.) Make sure you debug/compile and compact/repair the mdb. Also try it on another computer to see if it's something related to that specific computer and possibly the MSAccess installation.

    Also make sure you have a default printer setup as MSAccess doesn't like not having a default printer setup (strange things happen when there's no default printer setup on the computer.)
    Last edited by pkstormy; 01-25-10 at 19:27.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Sep 2006
    Posts
    265
    I have got my old PC running Access 97 and I found

    pdf 995: create PDF documents easily for free

    I didn't use this very often but I never had any problems with it.

    Simon

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •