Link to home
Start Free TrialLog in
Avatar of Enflow
EnflowFlag for United States of America

asked on

[b]Access 32Bit Work Fine 3Yrs - Convert 64Bit - No Joy[/b]

Access 32Bit Working Fine 3 Years... Trying To Convert to 64Bit... Not Working

In 64Bit Code the fail is on the LoadLibrary 64Bit function it does not load the library in the 64 vs the 32 code...

have all the dills in all the right places same for both and when i debug the CurrentDB dir is correct for Lib to load... color me confused.

Access 32Bit Code (working)
Option Explicit

Public Declare Function MergePDFDocuments Lib "StrStorage.dll" _
    (ByVal PDFMaster As String, _
    ByVal PDFChild As String _
    ) As Boolean
    
'IMPORTANT FOR LOADLIB FUNCTION
Private Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long

'IMPORTANT FOR LOADLIB FUNCTION
Private Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

'Instance returned from LoadLibrary calls
'IMPORTANT
Private hLibDynaPDF As Long
Private hLibStrStorage As Long

Public Function LoadLib() As Boolean
Dim s As String
Dim blRet As Boolean, A As String

On Error Resume Next

' *** Please Note ***
' If you are going to process many reports at once then to improve performance you
' should only call LoadLib once.

' May 16/2008
' Always look in the folder where this MDB resides First before checking the System folder.

LoadLib = False

' If we aready loaded then free the library
If hLibDynaPDF <> 0 Then
    hLibDynaPDF = FreeLibrary(hLibDynaPDF)
End If


' Our error string
s = "Sorry...cannot find the DynaPDF.dll file" & vbCrLf
s = s & "Please copy the DynaPDF.dll file into the same folder as this Access MDB or your Windows System32 folder."

' OK Try to load the DLL assuming it is in the same folder as this MDB.
' CurrentDB works with both A97 and A2K or higher
hLibDynaPDF = LoadLibrary(CurrentDBDir() & "DynaPDF.dll")
    
If hLibDynaPDF = 0 Then
    ' OK Try to load the DLL assuming it is in the Window System folder
    hLibDynaPDF = LoadLibrary("DynaPDF.dll")
End If

If hLibDynaPDF = 0 Then
    MsgBox s, vbOKOnly, "MISSING DynaPDF.dll FILE"
    LoadLib = False
    Exit Function
End If


' Load StrStorage.DLL
' If we aready loaded then free the library
If hLibStrStorage <> 0 Then
    hLibStrStorage = FreeLibrary(hLibStrStorage)
End If

' Our error string
s = "Sorry...cannot find the StrStorage.dll file" & vbCrLf
s = s & "Please copy the StrStorage.dll file into the same folder as this Access MDB or your Windows System32 folder."

' OK Try to load the DLL assuming it is in the same folder as this MDB.
' CurrentDB works with both A97 and A2K or higher
hLibStrStorage = LoadLibrary(CurrentDBDir() & "StrStorage.dll")

If hLibStrStorage = 0 Then
    ' OK Try to load the DLL assuming it is in the Window System folder
    hLibStrStorage = LoadLibrary("StrStorage.dll")
End If

If hLibStrStorage = 0 Then
    MsgBox s, vbOKOnly, "MISSING StrStorage.dll FILE"
    LoadLib = False
    Exit Function
End If

' RETURN SUCCESS
LoadLib = True
End Function

'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Private Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
    strDBPath = CurrentDb.NAME
    strDBFile = Dir(strDBPath)
    CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************

Open in new window


Trying To Do Access 64Bit - Code NOT Working
Option Explicit

Declare PtrSafe Function MergePDFDocuments Lib "StrStorage.dll" _
    (ByVal PDFMaster As String, _
    ByVal PDFChild As String _
    ) As Boolean
    
'IMPORTANT FOR LOADLIB FUNCTION
Private Declare PtrSafe Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long

[b]'IMPORTANT FOR LOADLIB FUNCTION
Private Declare PtrSafe Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long[/b]

'Instance returned from LoadLibrary calls
'IMPORTANT
Private hLibDynaPDF As Long
Private hLibStrStorage As Long

Public Function LoadLib() As Boolean
Dim s As String
Dim blRet As Boolean, A As String

On Error Resume Next

' *** Please Note ***
' If you are going to process many reports at once then to improve performance you
' should only call LoadLib once.

' May 16/2008
' Always look in the folder where this MDB resides First before checking the System folder.

LoadLib = False

' If we aready loaded then free the library
If hLibDynaPDF <> 0 Then
    hLibDynaPDF = FreeLibrary(hLibDynaPDF)
End If

' Our error string
s = "Sorry...cannot find the DynaPDF.dll file" & vbCrLf
s = s & "Please copy the DynaPDF.dll file into the same folder as this Access MDB or your Windows System32 folder."

[b]' OK Try to load the DLL assuming it is in the same folder as this MDB.
' CurrentDB works with both A97 and A2K or higher
hLibDynaPDF = LoadLibrary(CurrentDBDir() & "DynaPDF.dll")[/b]
    
If hLibDynaPDF = 0 Then
    ' OK Try to load the DLL assuming it is in the Window System folder
    hLibDynaPDF = LoadLibrary("DynaPDF.dll")
End If

If hLibDynaPDF = 0 Then
    MsgBox s, vbOKOnly, "MISSING DynaPDF.dll FILE"
    LoadLib = False
    Exit Function
End If


' Load StrStorage.DLL
' If we aready loaded then free the library
If hLibStrStorage <> 0 Then
    hLibStrStorage = FreeLibrary(hLibStrStorage)
End If

' Our error string
s = "Sorry...cannot find the StrStorage.dll file" & vbCrLf
s = s & "Please copy the StrStorage.dll file into the same folder as this Access MDB or your Windows System32 folder."

' OK Try to load the DLL assuming it is in the same folder as this MDB.
' CurrentDB works with both A97 and A2K or higher
hLibStrStorage = LoadLibrary(CurrentDBDir() & "StrStorage.dll")

If hLibStrStorage = 0 Then
    ' OK Try to load the DLL assuming it is in the Window System folder
    hLibStrStorage = LoadLibrary("StrStorage.dll")
End If

If hLibStrStorage = 0 Then
    MsgBox s, vbOKOnly, "MISSING StrStorage.dll FILE"
    LoadLib = False
    Exit Function
End If

' RETURN SUCCESS
LoadLib = True
End Function

'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Private Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
    strDBPath = CurrentDb.NAME
    strDBFile = Dir(strDBPath)
    CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************

Open in new window

Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

This is more a decision related issue than a programming issue.
I am afraid I am typing on my phone and it's hard to pinpoint you to a solution ...if there is one out there ( googling : VBA DynaPdf 64bit will give you plenty of threads on the issue)..but it boils down to this : are you going to go the trusted path of 32 bit that works out of the box and it's has proven over the years it's value or you will follow a marketing trick that puts pressure on the clients for switching to a new world ....64bit that has done almost nothing to provide support over pressing issues and just gives empty promises to the future
The issue that you are having is this:

Public Declare Function MergePDFDocuments Lib "StrStorage.dll" _
    (ByVal PDFMaster As String, _
    ByVal PDFChild As String _
    ) As Boolean

 That .dll must be compiled as 64 bit.  Just changing the call is only part of the step.   This is part of Stephan Leban's Report To PDF code.   Since he has now retired, you'll need to find another way of of sending reports to PDF as that DLL is 32 bit and there is no 64 bit version.

 What version of Access are you using?  Starting with Access 2007, there is now a PDF plugin for Access.   It doesn't give you much control however, but if your needs are simple output, you just need to install it.

 If you want more control, the other options are:

1. Output to Post Script and then convert to PDF with something like Ghost Script (https://www.ghostscript.com)
2. Use a PDF "printer" to generate the output, like  CutePDF, PDFExchange, or Adobe.
3. Buy a 3rd party lib that will do what Lebans code did for you.

 As far as converting to 64 bit, sooner or later you will have to, and there are some benefits.   But for the moment, you might want to stick with 32 bit until you can find solutions for your issues.

Jim.
Avatar of Enflow

ASKER

@John Tsioumpris...

1. Will look into DynaPDF 64Bit threads...

2. The change to 64Bit was from 'ON HIGH' against my advice... they new best...  :o)

thanks... CJ
Avatar of Enflow

ASKER

@Jim D...

""" That .dll must be compiled as 64 bit.  Just changing the call is only part of the step.   This is part of Stephan Leban's Report To PDF code.   Since he has now retired, you'll need to find another way of of sending reports to PDF as that DLL is 32 bit and there is no 64 bit version."""

I am being forced to go to Access 2016 64 Bit office by the 'On High Power Users Since They Know Best'

Right...

I use the Access VBA built in code and a PDF printer driver to output my PDFs... as....
DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath & "\" & strReportName, False

I can pop a 40 page PDF this way in 8 seconds with graphs, colors and text and grids... but...

Lebans Merge dlll did a GREAT job at merging a minor pdf into my main pdf on the fly in runtime.

Jim... What if i deconstruct the Merge dll... pull out the code and then recompile in a 64Bit dll... Never done by me... Is that a way to  go or is there another dll that will merge two PDFs via vba on the fly ?
The beloved 'On High Power Users'...and their indefinite wisdom....
Tough case...forget about messing with the .dll and such-like..it requires high quality programming skills ... unless you want to start a company of custom dlls..
My best recommendation would be: focus on the various PDF printers both free and paid...each carries it's own pros and cons...find the perfect balance bettween your needs and their reqs.
Hint : when this is over ...just approach one of the 'High Users'...and ask to name 1 advantage of 64bit vs 32.... probably the response you will get is 'but 64bit is the future...'...just walk out of the conversation knowing that 64bit need specific needs to show their benefits... otherwise resulting in slower..more memory hungry applications.
<<I am being forced to go to Access 2016 64 Bit office by the 'On High Power Users Since They Know Best'

Right... >>

  Well the one major reason for going to 64 bit is process address space.   With 32 bit, your limited to 2GB max for apps (leaving 2GB for the OS).   You can push that to 3GB if your app is Large Address Aware, but Access is not and I don't believe it ever will be.  LAA was a stop gap until we got to 64 bit, and Office and VBA have already been ported to that, so I'd highly doubt Microsoft would go back and add LAA to Access.

  So sooner or later everyone will be on 64 bit and the only real decision at this point is "when".   In the case of Access apps, almost everything available for it is only available in 32 bit and with Access being a mature product, most who did a lot of the utilities/freeware software have retired.  So everyone in the Access world is delaying this as long as possible.

<<Lebans Merge dlll did a GREAT job at merging a minor pdf into my main pdf on the fly in runtime.>>

  You'll have to find another lib to replace that then.    Ghostscript is the only lib I can think of off-hand that is free under a public license.   Don't know how it would work for you.   You could install it and try it from the command line to see if it will do what you need it to do.    If not, then you'll have to buy something.   CutePDF, PDFExchange, and Adobe all offer libs for purchase.

<<Jim... What if i deconstruct the Merge dll... pull out the code and then recompile in a 64Bit dll... Never done by me... Is that a way to  go or is there another dll that will merge two PDFs via vba on the fly ?>>

  That is another route, but I would suggest avoiding this unless you are already fluent with graphics/PDF files.   It's not so much the coding that is the problem, but having knowledge of the various formats and how to work with them.

 and if you've never done anything like deconstructing a DLL, that's a very big hill to climb.   You would come out ahead time/money wise by just buying something.

Jim.
If you need to merge PDFs, you might look into pdfTK or if your users actually own a copy of Acrobat, they can use automation to do that merge operation.
Avatar of Enflow

ASKER

@Jim D...

I found this website for GhostScript and merge PDFs on the Fly by Code...  

https://www.rgagnon.com/gp/gp-0015.html

Is this VB Script or what language ?

Should be easy to convert to VBA ?

gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 1.pdf 2.pdf 3.pdf

Now how to install or ref GhostScript in Access VBA ---  https://www.ghostscript.com/doc/9.21/Install.htm#Install_Windows

I see that GhostScript has a 64Bit dill for working with 64Big WINDOWS... but...

Okay... but I am NOT sure ghostsript will have a dll that will work with Office 64Bit Apps... -- Searching for info on that now...
Look at the PDF toolkit as Dale suggested. You can call it per shell as there is a command line version. It works without installing it, just drop the files somewhere in the path. For merge jobs the free version may be already sufficent.
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Enflow

ASKER

@Jim D...

Great Stuff... let me try that out... if work... upgrade to solution... thanks for the help... CJ
Avatar of Enflow

ASKER

Okay...

assigned solution points...

Rolled this over to another Question which needs to find the correct SYNTAX help to GET GhostScript to work for my MergeToPDF solution on 64Bit Office

Here is NEW Question...  https://www.experts-exchange.com/questions/29156370/Access-64Bit-GhostScript-64Bit-Merge-Two-PDFs.html#questionAdd