Hi Paul,
To initialize the controls of the userform to values in the bookmarks
to enable editing of previous entries, you need to grab those values
as the userform is preparing its appearance.
In the userform's code window in the VBA editor, there are two
dropdowns just below the toolbars. In the left dropdown, choose
"UserForm"; then in the right dropdown, choose "Activate". That
prepares this empty subroutine:
Private Sub UserForm_Activate()
End Sub
Between those lines, you can write code that will initialize the
contents of the text and combo boxes of the userform with whatever
values are in the bookmarks in the document. Here is sample code:
Private Sub UserForm_Activate()
Dim Depts As Variant
Dim strDept As String
Depts = Array("Sales", "Production", "Acquisitions")
' fill in text box
txtName.Text = _
ActiveDocument.Bookmarks("Name").Range.Text
' initialize combo box list and select value
With cbxDept
.Clear
.List = Depts
strDept = _
ActiveDocument.Bookmarks("Department").Range.Text
.Value = strDept
If Not .MatchFound Then
MsgBox "Invalid department " & strDept, _
vbOKOnly + vbCritical, "Error"
End If
End With
End Sub
Real working code should take into account the possibilities that the
bookmarks don't exist (the user deleted them or overwrote them) or
contain either nothing or invalid values.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
Thanks. I managed to run the example at
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
My users will have multiple data items from the left side, right side, both
or neither. I suppose that if I put all the relevant text and combo boxes
into a userform, on returning I can populate the two [sets of] bookmarks in
the document appropriately. It would be nice, if the user realises that he
has made a mistake, for him to be able to return to the userform and edit the
data fora second pass.
--
Paul Bishop
Graham Mayor said:
No you can't do that. You'll have to rethink the whole form in order to do
this. You can insert texts based upon the result of a form field eg
http://www.gmayor.com/SelectFile.htm but extra form fields are a different
matter. I would personally approach this using userforms and macros to call
further userforms based on the responses to create the finished document.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>