Hi there,
I've been working on an Access database to import Word documents from
formfield-based templates. As some of the form fields don't have names,
I've used some code I found on here to name them - however the contents
of the dropdowns are then reset to their defaults. I've tried to
capture the dropdown's value in a variable, but I get error messages
with everything I do to insert the variable's value back into the
field.
I've spent a day trying to capture the actual value rather than just a
rectangle; the best I seem to be able to manage now is overwriting the
formfield itself with the variable, which really doesn't help!
Please can someone help? I'm new to Word VBA (specifically the object
model!), I'm used to Access VBA!!
It seems to be using Word 2002; the code is stored in an Access 2002
database (2000 file format).
Before this, the document is identified, opened and unprotected.
For Each oFormfield In doc.FormFields
oFormfield.Select
If Selection.Bookmarks.Count = 0 Then
tmp = oFormfield.Result
oFormfield.Range.Fields.Locked = True
With Dialogs(wdDialogFormFieldOptions)
i = i + 1
.Name = "Formfield" & i
.Execute
End With
End If
'these are all the things I've tried and the error messages with each
'Selection.Collapse Direction:=wdCollapseEnd (deleted the previous
line, didn't work anyway).
'oFormfield.Result = tmp (application-defined or object-defined
error)
'oFormfield.Range.InsertAfter tmp (server throws an exception)
'MsgBox tmp (this is the only ducking thing which works!)
'doc.FormFields("oFormfield").Result = tmp (error 5941 - field not
found)
'doc.FormFields(oFormfield).Result ('bad parameter')
'Selection.TypeText tmp (this one overwrites the formfield)
'oFormfield.Range.Text = tmp (server throws an exception with this
one)
Next
Huge thanks!!
Chantal
Greg Maxey - 16 Oct 2006 16:14 GMT
Chantal,
I don't really follow all of your coding attempts, but if the problem
is the dropdowns resetting to their default value when you protect the
form then you should add the optional variant NoReset = True to the
code to protect the form.
ActiveDocument.Protect Type:=wdAllowOnlyComments, NoReset:=True
> Hi there,
>
[quoted text clipped - 51 lines]
>
> Chantal
chantal.lyn@gmail.com - 16 Oct 2006 17:27 GMT
Thanks - I'll try that tomorrow, but most of those errors were from
before I changed it from True to False.
> Chantal,
>
[quoted text clipped - 60 lines]
> >
> > Chantal
JCNZ - 20 Oct 2006 06:48 GMT
Hi Chantal:
If you know the order of the fields in the forms, you can simplify your
problem by saving only the data. It all gets dumped into a comma delimited
.txt file and you can easily suck it into your database from there. You don't
have to unprotect the form or do anything complex like that. Just set the
'Save data only for forms' option in the Save options dialog.
Good luck.
> Thanks - I'll try that tomorrow, but most of those errors were from
> before I changed it from True to False.
[quoted text clipped - 63 lines]
> > >
> > > Chantal