#1   Report Post  
Posted to microsoft.public.word.newusers
Michael Michael is offline
external usenet poster
 
Posts: 154
Default User Forms

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?
  #2   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default User Forms

In the Userform_Activate() procedure of the userform, you must create
code that gets the values of the bookmarks and puts those values into
the controls of the userform. This procedure runs just before the
userform appears on the screen.

For example, if you have a bookmark named "Address" in the document,
and a corresponding text box control named "tbxAddress" in the
userform, the Userform_Activate() procedure should include the line

tbxAddress.Text = ActiveDocument.Bookmarks("Address").Range.Text

You can use similar code to initialize check boxes, list boxes, and
other controls in the userform from data in the document.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sun, 7 Jan 2007 17:31:00 -0800, Michael
wrote:

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?

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

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?



  #4   Report Post  
Posted to microsoft.public.word.newusers
Michael Michael is offline
external usenet poster
 
Posts: 154
Default User Forms

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?




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








  #6   Report Post  
Posted to microsoft.public.word.newusers
Michael Michael is offline
external usenet poster
 
Posts: 154
Default User Forms

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?






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








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

BTW, the reason for using the If...then...Else... construction is to load
the variable with a space if the user does not enter anything into the
control on the user form. Without that, the variable would not be created
and then an error would occur if there was an attempt to get the values from
the variables to appear in the userform.

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








Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms w/blank spaces for user to fill in? Shelly Microsoft Word Help 1 August 24th 06 12:09 AM
Detach or change SQL data source for Word template, and other Qs SJMac Mailmerge 6 July 27th 06 10:12 AM
Validating Forms in MS Word Scott Microsoft Word Help 2 July 5th 06 03:15 PM
User Forms and Combo boxes in Work Kay Microsoft Word Help 2 December 17th 05 02:47 AM
How do I share ALL files with new user? Dick Microsoft Word Help 0 December 16th 05 09:23 PM


All times are GMT +1. The time now is 09:46 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"