Hello. I have an Access database, that has several command buttons that populates pdf forms with data from Access. It works great on my computer, but I have the full Adobe Acrobat program. I need it to be able to work with Adobe Reader, and I'm not sure if I have to change my code for this. I have 2 other co-workers that need to use it, and it's not working on theirs. When I tried to run it from their system, it err'd out on the module.
Can anyone help?
I have one module code:
Code:
Option Compare Database
Option Explicit
Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As LongPtr
'ShowWindow Enum
Public Enum eSE_ShowWindow
seswHide = 0
seswNormal = 1
seswShowMinimized = 2
seswShowMaximized = 3
seswShowNoActivate = 4
seswShow = 5
seswMinimize = 6
seswShowMinNoActive = 7
seswShowNA = 8
seswRestore = 9
seswShowDefault = 10
seswForceMinimize = 11
seswMax = 12
End Enum
'Operation enum
Public Enum eSE_Operation
seopDefault = -1
seopOpen = 0
seopPrint = 1
seopExplore = 2
seopRead = 3
seopProperties = 4
End Enum
'============================================================================
' NAME: ShellEx
' DESC: Calls ShellExecute API
'============================================================================
'ErrStrV3.00
Public Function ShellEx( _
sFile As String, _
Optional iOperation As eSE_Operation = seopDefault, _
Optional sParameters As String = "", _
Optional sDirectory As String = "", _
Optional lShowCmd As eSE_ShowWindow = seswNormal, _
Optional lHand As Long = 0 _
) As Boolean
On Error GoTo Error_Proc
Dim Ret As Boolean
'=========================
Dim sOp As String
'=========================
Select Case iOperation
Case seopOpen: sOp = "open"
Case seopPrint: sOp = "print"
Case seopExplore: sOp = "explore"
Case seopRead: sOp = "read"
Case seopDefault: sOp = vbNullChar
Case seopProperties: sOp = "properties"
Case Else: sOp = vbNullChar
End Select
If Len(sParameters) = 0 Then sParameters = vbNullString
If Len(sDirectory) = 0 Then sDirectory = vbNullString
Ret = IIf(apiShellExecute(lHand, sOp, sFile, sParameters, sDirectory, lShowCmd) > 32, True, False)
'=========================
Exit_Proc:
ShellEx = Ret
Exit Function
Error_Proc:
MsgBox "Error: " & Trim(Str(Err.Number)) & vbCrLf & _
"Desc: " & Err.Description & vbCrLf & vbCrLf & _
"Module: basShellExecute, Procedure: ShellEx" _
, vbCritical, "Error!"
Resume Exit_Proc
Resume
End Function
And this is the code for the pdf form.
Code:
Private Sub Command41_Click()
'theDBguy@gmail.com
'4/10/2012
'This demo creates a XFDF file to merge with a fillable PDF form.
'Using this method avoids the need to use an Acrobat DLL to manipulate the PDF file.
'This method relies on the capabilities of the installed PDF reader.
'Declare the PDF file to be filled and assume it's in the same directory as the database
Const strPDF As String = "URS Midwest ICSA 16.2.pdf"
'Declare the XFDF file to use
Const strXFDF As String = "URS Midwest ICSA.xfdf"
Dim strPath As String
Dim intFile As Integer
strPath = CurrentProject.Path
intFile = FreeFile
'Create XFDF file
Open strPath & "\" & strXFDF For Output As #intFile
'This is where I need to change the field names to match my pdf formm.
Print #intFile, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #intFile, "<xfdf xmlns=""http://ns.adobe.com/xfdf/"" xml:space=""preserve"">"
Print #intFile, "<f href=""" & strPDF & """/>"
Print #intFile, "<fields>"
Print #intFile, "<field name=""TruckNo"">"
Print #intFile, "<value>" & Me.TruckNo & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TrailerUnitNo"">"
Print #intFile, "<value>" & Me.TrailerUnitNo & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""DBA"">"
Print #intFile, "<value>" & Me.DBA & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TractorYear"">"
Print #intFile, "<value>" & Me.TractorYear & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TractorMake"">"
Print #intFile, "<value>" & Me.TractorMake & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TractorVIN"">"
Print #intFile, "<value>" & Me.TractorVIN & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TrailerYear"">"
Print #intFile, "<value>" & Me.TrailerYear & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""Trailermake"">"
Print #intFile, "<value>" & Me.Trailermake & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""TrailerVIN"">"
Print #intFile, "<value>" & Me.TrailerVIN & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""Expr1"">"
Print #intFile, "<value>" & Me.Expr1 & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""OwnerAddress1"">"
Print #intFile, "<value>" & Me.OwnerAddress1 & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""OwnerAddress2"">"
Print #intFile, "<value>" & Me.OwnerAddress2 & "</value>"
Print #intFile, "</field>"
Print #intFile, "<field name=""Expr2"">"
Print #intFile, "<value>" & Me.Expr2 & "</value>"
Print #intFile, "</field>"
Print #intFile, "</fields>"
Print #intFile, "</xfdf>"
Close #intFile
'Open the PDF file
ShellEx strPath & "\" & strXFDF
End Sub