Is it possible to populate a param array by looping through a table? I am calling function that uses a paramarray as a parameter, but it doesn't work if I try to pass an array to the paramarray parameter, only when I hard code in values.
eg Paramarray("value1","value2","value3").
hilbertl
'VERSION 1.0 CLASS
'BEGIN
' MultiUse = -1 'True
' Persistable = 0 'NotPersistable
' DataBindingBehavior = 0 'vbNone
' DataSourceBehavior = 0 'vbNone
' MTSTransactionMode = 0 'NotAnMTSObject
'End
'Attribute VB_Name = "CombinePDFs"
'Attribute VB_GlobalNameSpace = False
'Attribute VB_Creatable = True
'Attribute VB_PredeclaredId = False
'Attribute VB_Exposed = False
'Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
'Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private msProblem As String
'Public Event Status(ByVal sMessage As String)
Public Property Get Problem() As String
Problem = msProblem
End Property
Public Function Combine(ByVal sOutputFile As String, ParamArray SourceFiles()) As Boolean
' files will be combined in the order they were added to SourceFiles()
Dim i As Long
Dim nLB As Long
Dim nUB As Long
Dim nRet As VbMsgBoxResult
Dim oOutputPDF As Acrobat.CAcroPDDoc
Dim oInputPDF As Acrobat.CAcroPDDoc
Dim nPagesTo As Long
Dim nPagesFrom As Long
On Error GoTo ERRHANDLER
Combine = False
nLB = LBound(SourceFiles)
nUB = UBound(SourceFiles)
If nUB < nLB Then
Err.Raise vbObjectError + 6001, "Combine", "No files to combine"
Else
Set oOutputPDF = CreateObject("AcroExch.PDDoc")
' RaiseEvent Status("Opening " & SourceFiles(nLB))
If Not oOutputPDF.Open(SourceFiles(nLB)) Then
Err.Raise vbObjectError + 6002, "Combine", "Unable to open " & SourceFiles(nLB)
End If
nPagesTo = oOutputPDF.GetNumPages
For i = (nLB + 1) To nUB
Set oInputPDF = CreateObject("AcroExch.PDDoc")
' RaiseEvent Status("Opening " & SourceFiles(i))
If Not oInputPDF.Open(SourceFiles(i)) Then
Err.Raise vbObjectError + 6003, "Combine", "Unable to open " & SourceFiles(i)
End If
nPagesFrom = oInputPDF.GetNumPages
' RaiseEvent Status("Inserting " & nPagesFrom & " pages from " & SourceFiles(i))
If Not oOutputPDF.InsertPages(nPagesTo - 1, oInputPDF, 0, nPagesFrom, True) Then
Err.Raise vbObjectError + 6004, "Combine", "Unable to add " & SourceFiles(i)
End If
nPagesTo = oOutputPDF.GetNumPages
Set oInputPDF = Nothing
Next i
'RaiseEvent Status("Saving " & sOutputFile)
If Not oOutputPDF.Save(PDSaveFull, sOutputFile) Then
Err.Raise vbObjectError + 6005, "Combine", "Unable to save " & sOutputFile
End If
' RaiseEvent Status("Closing " & sOutputFile)
Call oOutputPDF.Close
Set oOutputPDF = Nothing
Combine = True
End If
Exit Function
ERRHANDLER:
' msProblem = Err.Description
' nRet = MsgBox("Error " & Err.Number & ": " & Err.Description, _
'' vbQuestion + vbRetryCancel, App.Title & " - " & Err.Source)
'If nRet = vbRetry Then Resume
'Combine = False
'Set oOutputPDF = Nothing
'Set oInputPDF = Nothing
End Function
eg Paramarray("value1","value2","value3").
hilbertl
'VERSION 1.0 CLASS
'BEGIN
' MultiUse = -1 'True
' Persistable = 0 'NotPersistable
' DataBindingBehavior = 0 'vbNone
' DataSourceBehavior = 0 'vbNone
' MTSTransactionMode = 0 'NotAnMTSObject
'End
'Attribute VB_Name = "CombinePDFs"
'Attribute VB_GlobalNameSpace = False
'Attribute VB_Creatable = True
'Attribute VB_PredeclaredId = False
'Attribute VB_Exposed = False
'Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
'Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private msProblem As String
'Public Event Status(ByVal sMessage As String)
Public Property Get Problem() As String
Problem = msProblem
End Property
Public Function Combine(ByVal sOutputFile As String, ParamArray SourceFiles()) As Boolean
' files will be combined in the order they were added to SourceFiles()
Dim i As Long
Dim nLB As Long
Dim nUB As Long
Dim nRet As VbMsgBoxResult
Dim oOutputPDF As Acrobat.CAcroPDDoc
Dim oInputPDF As Acrobat.CAcroPDDoc
Dim nPagesTo As Long
Dim nPagesFrom As Long
On Error GoTo ERRHANDLER
Combine = False
nLB = LBound(SourceFiles)
nUB = UBound(SourceFiles)
If nUB < nLB Then
Err.Raise vbObjectError + 6001, "Combine", "No files to combine"
Else
Set oOutputPDF = CreateObject("AcroExch.PDDoc")
' RaiseEvent Status("Opening " & SourceFiles(nLB))
If Not oOutputPDF.Open(SourceFiles(nLB)) Then
Err.Raise vbObjectError + 6002, "Combine", "Unable to open " & SourceFiles(nLB)
End If
nPagesTo = oOutputPDF.GetNumPages
For i = (nLB + 1) To nUB
Set oInputPDF = CreateObject("AcroExch.PDDoc")
' RaiseEvent Status("Opening " & SourceFiles(i))
If Not oInputPDF.Open(SourceFiles(i)) Then
Err.Raise vbObjectError + 6003, "Combine", "Unable to open " & SourceFiles(i)
End If
nPagesFrom = oInputPDF.GetNumPages
' RaiseEvent Status("Inserting " & nPagesFrom & " pages from " & SourceFiles(i))
If Not oOutputPDF.InsertPages(nPagesTo - 1, oInputPDF, 0, nPagesFrom, True) Then
Err.Raise vbObjectError + 6004, "Combine", "Unable to add " & SourceFiles(i)
End If
nPagesTo = oOutputPDF.GetNumPages
Set oInputPDF = Nothing
Next i
'RaiseEvent Status("Saving " & sOutputFile)
If Not oOutputPDF.Save(PDSaveFull, sOutputFile) Then
Err.Raise vbObjectError + 6005, "Combine", "Unable to save " & sOutputFile
End If
' RaiseEvent Status("Closing " & sOutputFile)
Call oOutputPDF.Close
Set oOutputPDF = Nothing
Combine = True
End If
Exit Function
ERRHANDLER:
' msProblem = Err.Description
' nRet = MsgBox("Error " & Err.Number & ": " & Err.Description, _
'' vbQuestion + vbRetryCancel, App.Title & " - " & Err.Source)
'If nRet = vbRetry Then Resume
'Combine = False
'Set oOutputPDF = Nothing
'Set oInputPDF = Nothing
End Function