I'm opening a word document from within MsAccess, then writing the field count and field results to a text file for import into a survey table. The field count is later mapped to the question id in the master survey table. The text file and header for the text file are created in the preceding procedure.
This code won't work (at least I can't get it to) unless I remark out "Dim afield as word.field". This boggles my mind, afield is referenced throughout the procedure, how can it possibly work and how do I fix this?! Thanks in advance. Sorry if I didn't do the [Code] tags right...Also attached the output of the text file (temp1).
[Code]
Sub GetFld()
Dim count As Integer
'Dim afield As Word.Field
On Error Resume Next
Open "G:\Desktop\Temp1.txt" For Append As #1
count = 0
For Each afield In ActiveDocument.FormFields
'If afield.Type = wdFieldFormTextInput Then
count = count + 1
'Debug.Print count & "," & afield.Result
'Else: count = count
Print #1, """" & count & """" & Chr(59) & """" & afield.Result & """" & Chr(59) & """" & ActiveDocument.FormFields("Text3").Result & """"
Next afield
Close #1
'MsgBox "output complete"
End Sub
[Code]