how to access fields whose names have blanks at the end?
Hello everyone,
I've come across some tricky issue while accessing the values of my fomular fields. Some of them had blanks at the end, so when I tried to access them like this ...
Private Sub GetFormularValues(ByVal p_arrElement As String, p_intColumn As Integer)
Dim AcroApp As Acrobat.CAcroApp
Dim AcroPDDoc As Acrobat.CAcroPDDoc
Dim AcroAVDoc As Acrobat.CAcroAVDoc
Dim JSO As Object
Dim i As Integer
Dim f As Object
Dim fn As String
Set AcroApp = CreateObject("AcroExch.App")
Set AcroPDDoc = CreateObject("AcroExch.PDDoc")
'/ Check if the document can be opened for access
If AcroPDDoc.Open(p_arrElement) Then
Set JSO = AcroPDDoc.GetJSObject
With JSO
'/ If there are fields in the document, write their values onto first sheet
If .numFields Then
Application.ScreenUpdating = False
For i = 0 To .numFields - 1
fn = .getNthFieldName(i)
Set f = .getField(fn)
Sheet1.Cells(p_intColumn, (i + 1)).Value = f.Value
Debug.Print f.Value
Next i
Application.ScreenUpdating = True
Else
MsgBox p_arrElement & " is empty!.")
End If
End With
AcroPDDoc.Close
End If
'/ Exit Acrobat and clear everything
With AcroApp
.CloseAllDocs
.Hide
.Exit
End With
Set JSO = Nothing
Set AcroPDDoc = Nothing
Set AcroApp = Nothing
End Sub
... Excel will crash saying Runtime Error '424' and that there is no object. In detail, it will crash at this line:
Set f = .getField(fn)
while fn has been set to "field1 " here (with blank at the end):
fn = .getNthFieldName(i)
Does anybody know how I could access that fields' value even if its name has a blank at the end?
Thank you
Kind regards
Perry
