Thread: User Forms
View Single Post
  #5   Report Post  
Posted to microsoft.public.word.newusers
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default User Forms

Here's the code from a userform that uses that approach to enter the
information into the document and to load it back into the userform if the
form is run once again

Private Sub CommandButton1_Click()
With ActiveDocument
If txtCompany = "" Then
.Variables("Company").Value = " "
Else
.Variables("Company").Value = txtCompany
End If
If txtProject = "" Then
.Variables("Project").Value = " "
Else
.Variables("Project").Value = txtProject
End If
If txtDocNum = "" Then
.Variables("DocNum").Value = " "
Else
.Variables("DocNum").Value = txtDocNum
End If
If txtRevNum = "" Then
.Variables("Revision").Value = " "
Else
.Variables("Revision").Value = txtRevNum
End If
If txtDocTitle = "" Then
.Variables("DocTitle").Value = " "
Else
.Variables("DocTitle").Value = txtDocTitle
End If
.Fields.Update
.Sections(1).Headers(wdHeaderFooterPrimary).Range. Fields.Update
.Bookmarks("Text").Range.Select
End With
Unload Me
End Sub

Private Sub UserForm_Initialize()
With ActiveDocument
txtCompany = .Variables("Company").Value
txtProject = .Variables("Project").Value
txtDocNum = .Variables("DocNum").Value
txtRevNum = .Variables("Revision").Value
txtDocTitle = .Variables("DocTitle").Value
End With
txtDocNum.SetFocus
End Sub


--
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

"Michael" wrote in message
...
Sounds great. How to do using UserForms?

"Doug Robbins - Word MVP" wrote:

I would suggest that you use DocVariable fields instead of bookmarks as
all
you need to do then is load the controls on the form with the values in
the
document variables and replacing the data in the document is easier with
DocVariables rather than bookmarks as you will probably need code to
re-create the bookmark if you change the data that is in it.

--
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

"Michael" wrote in message
...
I have created a User Form that runs when the document opens that
propmts
for
data to be entered. This data is then attributed to bookmarks within
the
document.
I have created a macro that recalls the User Form so that I can change
data
is necessary, however when the User Form is recalled it is blank and
does
not
recognise the previously inserted information.

How do I fix this?