Thread: User Forms
View Single Post
  #7   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

Are you sure that the names of the controls on the form are identical to
what the code is expecting:

For example,

..Variables("Company").Value = txtComp

is there a control named txtComp?

In the code, if you insert a period after txtComp, the intellisense should
give you a list of attributes to choose. The one that you want is the .Text
one which is the default.

If the list doesn't appear, then the name used in the code is not the name
of a control on your form.

--
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
news
Hi Doug,
Thanks for your help. I have inserted DocVariable fields in the document
and copied the code below into VB so it reads as follows:

Private Sub Cancel_Click()
UserForm1.Hide
End Sub

Private Sub Image1_Click()

End Sub

Private Sub OK_Click()
With ActiveDocument
If txtComp = "" Then
.Variables("Company").Value = " "
Else
.Variables("Company").Value = txtComp
End If
If txtAtt = "" Then
.Variables("Attention").Value = " "
Else
.Variables("Attention").Value = txtAtt
End If
If txtFax = "" Then
.Variables("FaxNo").Value = " "
Else
.Variables("FaxNo").Value = txtFax
End If
If txtDay = "" Then
.Variables("Date").Value = " "
Else
.Variables("Date").Value = txtDay
End If
If txtPages = "" Then
.Variables("NoPages").Value = " "
Else
.Variables("NoPages").Value = txtPages
End If
If txtTopic = "" Then
.Variables("Subject").Value = " "
Else
.Variables("Subject").Value = txtTopic
End If
.Fields.Update

End With
Unload Me
End Sub

Private Sub UserForm_Click()
With ActiveDocument
txtComp = .Variables("Company").Value
txtAtt = .Variables("Attention").Value
txtFax = .Variables("FaxNo").Value
txtDay = .Variables("Date").Value
txtPages = .Variables("NoPages").Value
txtTopic = .Variables("Subject").Value
End With

End Sub

When the UserForm runs a balnk space is entered into the DocVariable field
rather than the text I enter into the text boxes.

Any ideas why this might be happening?

Thanks,

Mike.


"Doug Robbins - Word MVP" wrote:

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?