Copy link to clipboard
Copied
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
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 PopulateListOrComboBo
...Copy link to clipboard
Copied
PopulateListOrComboBox does not appear in my documentation. how do you come to use it?
Copy link to clipboard
Copied
I was searching how to fill the combobox's list and found:
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you George !
Special but it does the job.