Skip to main content
Participating Frequently
June 14, 2016
Answered

VBA - Acrobat DC Pro - AFormAut - PopulateListOrComboBox

  • June 14, 2016
  • 2 replies
  • 2384 views

Hi,

I'm trying to fill a combobox with wsh (or vba).

I get an error "Invalid arguments" when calling PopulateListOrComboBox.

Can you help for the correct syntax ?

I tried with 1 or 2 arguments.

Ex code:

Sub Test()

    Dim oAcrobat

    Dim oAVDoc

    Dim oForm

    Dim arr

    Dim arr2

    Dim oField

    Set oAcrobat = CreateObject("AcroExch.App")

    Set oAVDoc = CreateObject("AcroExch.AVDoc")

    Set oForm = CreateObject("AFormAut.App")

  

    oAVDoc.Open "C:\Dev\KExtAcrobat\ak.pdf", "ak.pdf"

  

    arr = Array("1", "2")

    arr2 = Array("1", "2")

  

    Set oField = oForm.Fields.Item("Dropdown1")

  

    oField.PopulateListOrComboBox arr, arr2

  

    Set oField = Nothing

  

    Set oAcrobat = Nothing

    Set oAVDoc = Nothing

    Set oForm = Nothing

End Sub

This topic has been closed for replies.
Correct answer George_Johnson

It's a bit more tedious, but you can always do something like:

Dim oAcrobat

Dim oAVDoc

Dim oForm

Set oAcrobat = CreateObject("AcroExch.App")

Set oAVDoc = CreateObject("AcroExch.AVDoc")

Set oForm = CreateObject("AFormAut.App")

oAVDoc.Open "C:\Dev\KExtAcrobat\ak.pdf\ak.pdf", "ak.pdf"

oForm.Fields.ExecuteThisJavascript "getField('Dropdown1').setItems([['1', 'ExpVal1'], ['2', 'ExpVal2']])"

Set oForm = Nothing

Set oAVDoc = Nothing

Set oAcrobat = Nothing

I seem to recall a problem with using PopulateListOrComboBox from a long time ago, but can't locate any useful info now. I switched to using Fields.ExecuteThisJavaScript for most things long ago because it just works better. You can define variables and functions in folder-level or document-level JavaScripts to make it easier to manage.

2 replies

Legend
June 14, 2016

Thank you, I was looking in the wrong place (JavaScript Fields object, not IAC OLE Fields object).

This segment looks OK,

   arr = Array("1", "2")

    arr2 = Array("1", "2") 

    Set oField = oForm.Fields.Item("Dropdown1") 

    oField.PopulateListOrComboBox arr, arr2

and seems match the documentation where each of the arguments is "an array of strings". However, I don't know VB/VBA to be sure that this matches. I also suggest double checking that the field name is exactly as given, and it really is a list or combo box.

Participating Frequently
June 14, 2016

Thank you for the reply.

Yes field name is ok and is a combobox (Msgbox oField.Type).

I tried to add a field and fill it and get the same error when calling PopulateListOrComboBox (wrong argument or call of procedure):

The field "test" is well created.

oForm.Fields.Add "test", "combobox", 0, 0, 800, 100, 810

Set oField = oForm.Fields.Item("test")

oField.PopulateListOrComboBox arr, arr2

Have you another suggestion ?

George_JohnsonCorrect answer
Inspiring
June 15, 2016

It's a bit more tedious, but you can always do something like:

Dim oAcrobat

Dim oAVDoc

Dim oForm

Set oAcrobat = CreateObject("AcroExch.App")

Set oAVDoc = CreateObject("AcroExch.AVDoc")

Set oForm = CreateObject("AFormAut.App")

oAVDoc.Open "C:\Dev\KExtAcrobat\ak.pdf\ak.pdf", "ak.pdf"

oForm.Fields.ExecuteThisJavascript "getField('Dropdown1').setItems([['1', 'ExpVal1'], ['2', 'ExpVal2']])"

Set oForm = Nothing

Set oAVDoc = Nothing

Set oAcrobat = Nothing

I seem to recall a problem with using PopulateListOrComboBox from a long time ago, but can't locate any useful info now. I switched to using Fields.ExecuteThisJavaScript for most things long ago because it just works better. You can define variables and functions in folder-level or document-level JavaScripts to make it easier to manage.

Legend
June 14, 2016

PopulateListOrComboBox does not appear in my documentation. how do you come to use it?

Participating Frequently
June 14, 2016