Sunday, March 28, 2010

Retrieving field names on a form

Hi,

I have used the below code to retieve field names from a form with Acrobat 5. This has worked fine, we have now upgraded to Acrobat 9 and the same code errors when executing the line 'Set fields = AFORMAUT.flelds' I am getting a type mismatch error. This is a simple funtion in VB6 which retrieves the field names and their associated types in a comma seperated string?

Does anyone know why this code does not work in Acrobat 9? or is there a better way to achieve the same results with Acrobat 9?

Thanks

Public Function fieldList(ByVal formName As String, ofields As String, otypes As String)
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 Dim AFORMAUT As AFORMAUTLib.AFormApp
聽聽聽 Dim fields As AFORMAUTLib.fields
聽聽聽 Dim Field As AFORMAUTLib.Field
聽聽聽 Dim AcroExchAVDoc As CAcroAVDoc
聽聽聽 Dim bOK As Boolean
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 On Error GoTo ErrorHandler

聽聽聽 Set AcroExchAVDoc = CreateObject(''AcroExch.AVDoc'')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 bOK = AcroExchAVDoc.Open(''C:\IHT400.PDF'', '''')
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 'If everything was OK opening the PDF, you can now instantiate the
聽聽聽 'Forms Automation object

聽聽聽 If (bOK) Then聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Set AFORMAUT = CreateObject(''AFormAut.App'')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Set fields = AFORMAUT.fields ' this line errors
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 For Each Field In fields
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 If Field.IsTerminal Then
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 If ofields = '''' Then
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ofields = Field.Name
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 otypes = Field.Type
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ofields = ofields + '','' + Field.Name
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 otypes = otypes + '','' + Field.Type
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 End If
聽聽聽聽聽聽聽聽聽聽聽 End If
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Next Field

聽聽聽聽聽聽聽 bOK = AcroExchAVDoc.Close(True)
聽聽聽聽聽聽聽
聽聽聽 End If
聽聽
Set AcroExchAVDoc = Nothing
Set AFORMAUT = Nothing
Set Field = Nothing
聽聽
ErrorHandler:
聽聽聽 MsgBox ''FieldList Error: '' + Err.Number + '' '' + Err.Description + '' '' + Err.Source
聽聽聽 Resume Next
End Function

Retrieving field names on a form

Was the form created with Adobe Acrobat?

Retrieving field names on a form

I assume it has, I have attached the form - if you want to have a look yourself.

Thanks


Can you post a link of the form?


He added it as an attachment but it hasn't been approved yet, it's still in the queue.聽 You'll be able to download the attachment soon once a forum admin approves it.


The form has been created using Acrobat, has anyone got any ideas on this?

Thanks


HI,

Just looking at the sample in the Acrobat 9 SDK and it has two references included in it.

Adobe Acrobat 9.0 Type Library ( as expected )

AFormAut 1.0 Type Library

the AFormAut library would appear to be the one that is needed for the object you are using, I don't have access to Acrobat 5 sdk, but I think it all used to be one library.

Just thought it was worth mentioning so you could make sure you have all the references you need,

Malcolm


Hi,

Thanks for the replies, I have since found that to get the field lists in Acrobat 9 then AcroExchAVDOC.BringToFront and AcroExchApp.Hide need to be used. As without these the Acrobat object thinks there is no form loaded. I have put the AxcroExchApp.Hide in as when your automating you don't want the acrobat program to be shown - there is a slight flash - but it is minimal.

This seems to be the only solution unless, anybody has got any other suggestions?

So my revised code is (changes in bold):-

Public Function fieldList(ByVal formName As String, ofields As String, otypes As String)
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 Dim AcroExchAVDoc As CAcroAVDoc
聽聽聽 Dim AcroExchApp As CAcroApp
聽聽聽
聽聽聽 Dim AFORMAUT As AFORMAUTLib.AFormApp
聽聽聽 Dim FormField As AFORMAUTLib.Field
聽聽聽 Dim FormFields As AFORMAUTLib.fields
聽聽聽 Dim bOK As Boolean
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 Dim FieldName As String
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 On Error GoTo ErrorHandler
聽聽聽
聽聽聽 Set AcroExchApp = CreateObject(''AcroExch.App'')
聽聽聽
聽聽聽 Set AcroExchAVDoc = CreateObject(''AcroExch.AVDoc'')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽 'formName
聽聽聽 bOK = AcroExchAVDoc.Open(''C:\PDFForm.pdf'', '''')
聽聽聽聽聽聽
聽聽聽 AcroExchAVDoc.BringToFront
聽聽聽
聽聽聽 AcroExchApp.Hide
聽聽聽
聽聽聽 'If everything was OK opening the PDF, you can now instantiate the
聽聽聽 'Forms Automation object

聽聽聽 If (bOK) Then
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Set AFORMAUT = CreateObject(''AFormAut.App'')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Set FormFields = AFORMAUT.fields
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 For Each FormField In FormFields
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 FieldName = FormField.Name
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 If FormField.IsTerminal Then
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 If ofields = '''' Then
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ofields = FormField.Name
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 otypes = FormField.Type
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ofields = ofields + '','' + FormField.Name
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 otypes = otypes + '','' + FormField.Type
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 End If
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽 End If
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 Next FormField

聽聽聽聽聽聽聽 AcroExchAVDoc.Close (True)
聽聽聽聽聽聽聽
聽聽 End If
聽聽聽聽聽聽聽
Set AcroExchAVDoc = Nothing
Set AcroExchApp = Nothing
Set AFORMAUT = Nothing
Set Field = Nothing
聽聽聽聽聽聽聽聽
ErrorHandler:
聽聽聽 MsgBox ''FieldList Error: '' + Str(Err.Number) + '' '' + Err.Description + '' '' + Err.Source
聽聽聽
End Function

Thanks

No comments:

Post a Comment