
Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
I figured out the reason. It was because the document was protected. When
I unprotected the document and re-opened it worked. I would like to
protect the document before it is displayed - is that possible? Also, I
finished building the form and have changed the command button name to
'cmdUpdate' from 'cmdSave' and now I am getting the following error:
Compile error: Invalid use of property. when running this set of code:
Private Sub cmdUpdate_Click()
With ActiveDocument
.Bookmarks("txtLName").Range _
.InsertBefore txtLName
.Bookmarks("txtFName").Range _
.InsertBefore txtFName
.Bookmarks("dte1").Range _
Thank you for your help...
Linda Aldrich
_____________________
> What does the error message say and if you click on Debug, what line of
> code is highlighted.
[quoted text clipped - 54 lines]
>>> Cheers
>>> TonyS.
Linda Aldrich - 14 Mar 2008 21:48 GMT
I think I have this question answered -- I created a macro to generate the
code below to protect a document after leaving the userform:
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyFormFields
>I figured out the reason. It was because the document was protected. When
>I unprotected the document and re-opened it worked. I would like to
[quoted text clipped - 74 lines]
>>>> Cheers
>>>> TonyS.
I found the resolution to the Compile Error. I had a space before my
commented text. Once I removed the space, the code ran fine. Still looking
forward to help with the macrobutton for the follow-on columns.
And, another question to boot! I ran the UserForm1 and populated some of
the fields on the form, but would like to be able to finish populating those
fields from the userform if the user has updates later. When I ran Tools,
Macros, Autonew, it showed the UserForm1 with the previously entered values,
which I thought good, it saved them in the form, but now -- I would like to
add values to two more fields and select cmdUpdate. When I did, it
re-inserted a second set of values for all of the previously populated
fields. Is there a way that I can tell it to replace the text in the
bookmark with the new value?
Thanks again for all of your help.
Linda Aldrich
> What does the error message say and if you click on Debug, what line of
> code is highlighted.
[quoted text clipped - 54 lines]
>>> Cheers
>>> TonyS.
Doug Robbins - Word MVP - 15 Mar 2008 02:56 GMT
If you want to reload the form with data/add additional data to the form
like you are doing, it would be better to have the information displayed in
the document by the use of { DOCVARIABLE varname } fields and set the values
of the variables to the data entered into the form.
Say you had a control on your form into which the patient's name was added
and that you have named that control txtPatientName, then in the template,
where you want the patient's name to appear, you would insert the following
field
{ DOCVARIABLE varPatientName }
and, in the CommandButton Click event, you would have the following code
With ActiveDocument
If len(txtPatientName) > 0 Then
.Variables("varPatientName").Value = txtPatientName
Else
.Variables("varPatientName").Value = " "
End If
'similarly for the other controls/variables
.Fields.Update
End With
The reason for the If ... Else ... End If statement is to prevent the
DOCVARIABLE field from displaying an error if its value is Nul. The
.Fields.Update is to update the fields in the document so that the
DOCVARIABLE fields show the values of the variables.
This way, the data will not be duplicated as is being done with the
bookmarks.
When you are reloading the form, to have the data that was already contained
in variables in the document, you would use the following code in the
Initialize() event of the form
With ActiveDocument
txtPatientName.Text = .Variables("varPatientName").Value
'Similarly for the other controls/variables
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I found the resolution to the Compile Error. I had a space before my
>commented text. Once I removed the space, the code ran fine. Still
[quoted text clipped - 72 lines]
>>>> Cheers
>>>> TonyS.