how to access fields whose names have blanks at the end?

Community Beginner ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

192

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Use a folder level function like this:

function GetFieldValue (doc, ind)

{

  return doc.getField(doc.getNthFieldName(ind)).valueAsString;

}

and use the function in your code.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2019 Jul 09, 2019

Copy link to clipboard

Copied

Hey Bernd,

thanks for your advice. Unfortunately I am stuck to Excel VBA with no access to the folder, where Adobe is installed to.

So I won't be able to use a .js script.

Anyway I will try to use your function in VBA but I doubt it will work.

Any further help is appreciated.

Kind regards

Perry

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

You can install the script in the Javascript folder of the user.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines