#1   Report Post  
Posted to microsoft.public.word.docmanagement
Erik Witkop Erik Witkop is offline
external usenet poster
 
Posts: 4
Default userform question

I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my VBA
script. So how can I populate data with a userform where I can reuse a
variable in the document. I want to populate 'customer' in 5 different
places in the doc. And bookmarks don't cut it.

Can anyone suggest a better way to get this done?

Thanks.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
Default userform question

Once you've inserted Customer at a bookmark (without overwriting it; see
http://word.mvps.org/FAQs/MacrosVBA/...tBookmark.htm), you can
use a REF field to repeat the content elsewhere. Or you can use five
bookmarks named Customer1, Customer2, etc. It's not that much more trouble
for your UserForm code to insert the field five times.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Erik Witkop" wrote in message
...
I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my VBA
script. So how can I populate data with a userform where I can reuse a
variable in the document. I want to populate 'customer' in 5 different
places in the doc. And bookmarks don't cut it.

Can anyone suggest a better way to get this done?

Thanks.



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default userform question

Use Document Variables and DOCVARIABLE fields instead of bookmarks



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

"Erik Witkop" wrote in message
...
I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my VBA
script. So how can I populate data with a userform where I can reuse a
variable in the document. I want to populate 'customer' in 5 different
places in the doc. And bookmarks don't cut it.

Can anyone suggest a better way to get this done?

Thanks.



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Erik Witkop Erik Witkop is offline
external usenet poster
 
Posts: 4
Default userform question

On May 12, 12:06*am, "Doug Robbins - Word MVP"
wrote:
Use Document Variables and DOCVARIABLE fields instead of bookmarks

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

"Erik Witkop" wrote in message

...



I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my VBA
script. So how can I populate data with a userform where I can reuse a
variable in the document. I want to populate 'customer' in 5 different
places in the doc. And bookmarks don't cut it.


Can anyone suggest a better way to get this done?


Thanks.- Hide quoted text -


- Show quoted text -


Thanks Doug. That is a much better solution that bookmarking. Working
with bookmarks is a pain.

Do you have any basic code to take a textfield from a userform and
populate a docvariable? I couldn't find any code that worked in
conjuction with userforms?

Thanks.
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default userform question

Erik Witkop wrote:
On May 12, 12:06 am, "Doug Robbins - Word MVP"
wrote:
Use Document Variables and DOCVARIABLE fields instead of bookmarks

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

"Erik Witkop" wrote in message

...



I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my
VBA script. So how can I populate data with a userform where I can
reuse a variable in the document. I want to populate 'customer' in
5 different places in the doc. And bookmarks don't cut it.


Can anyone suggest a better way to get this done?


Thanks.- Hide quoted text -


- Show quoted text -


Thanks Doug. That is a much better solution that bookmarking. Working
with bookmarks is a pain.

Do you have any basic code to take a textfield from a userform and
populate a docvariable? I couldn't find any code that worked in
conjuction with userforms?

Thanks.


The exact form of the code depends on where you place it (within the
userform's code, such as in the _Click procedure of the OK button; or in the
macro that declares and shows the userform).

If it's in the userform code, it could be something like this:

ActiveDocument.Variables("NameOfVariable").Value = TextBox1.Text

If it's in the calling macro, the left side is the same but "TextBox1" must
be addressed as a property of the userform:

Dim UF As UserForm1
Set UF = New UserForm1
UF.Show
ActiveDocument.Variables("NameOfVariable").Value = UF.TextBox1.Text

Don't take the latter as production code; at the very least, there's more
that needs to be done to make it error-resistant.

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




  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Erik Witkop Erik Witkop is offline
external usenet poster
 
Posts: 4
Default userform question

On May 13, 9:49 am, "Jay Freedman" wrote:
Erik Witkop wrote:
On May 12, 12:06 am, "Doug Robbins - Word MVP"
wrote:
Use Document Variables and DOCVARIABLE fields instead of bookmarks


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


"Erik Witkop" wrote in message


...


I built my own userform in VBA. And it works by populating bookmarks
in the word document. But I find I can only have 1 bookmark named
"customer" for example. So this does not scale well at all for my
VBA script. So how can I populate data with a userform where I can
reuse a variable in the document. I want to populate 'customer' in
5 different places in the doc. And bookmarks don't cut it.


Can anyone suggest a better way to get this done?


Thanks.- Hide quoted text -


- Show quoted text -


Thanks Doug. That is a much better solution that bookmarking. Working
with bookmarks is a pain.


Do you have any basic code to take a textfield from a userform and
populate a docvariable? I couldn't find any code that worked in
conjuction with userforms?


Thanks.


The exact form of the code depends on where you place it (within the
userform's code, such as in the _Click procedure of the OK button; or in the
macro that declares and shows the userform).

If it's in the userform code, it could be something like this:

ActiveDocument.Variables("NameOfVariable").Value = TextBox1.Text

If it's in the calling macro, the left side is the same but "TextBox1" must
be addressed as a property of the userform:

Dim UF As UserForm1
Set UF = New UserForm1
UF.Show
ActiveDocument.Variables("NameOfVariable").Value = UF.TextBox1.Text

Don't take the latter as production code; at the very least, there's more
that needs to be done to make it error-resistant.

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



Thanks Jay,

But for the life of me I cannot get this working. This is my code.


1. one form with one field. The form name is UserForm1. The field name
is customer_field.
2. one variable in the word doc named 'customer_var'


My code is this:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub CommandButton1_Click()
With ActiveDocument

.Variables("customer_var").Value = customer_field.Text
.Fields.Update

End With
End Sub

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

What is not happening, is the docvariable in the word doc never gets
populated. I don't get any debug errors, it simply does not populate
the docvariable in my word doc.

Any thoughts?

Thanks for all your help. There is very little flaming here as long as
you follow the rules. I like that.
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default userform question

Erik Witkop wrote:
Thanks Jay,

But for the life of me I cannot get this working. This is my code.


1. one form with one field. The form name is UserForm1. The field name
is customer_field.
2. one variable in the word doc named 'customer_var'


My code is this:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub CommandButton1_Click()
With ActiveDocument

.Variables("customer_var").Value = customer_field.Text
.Fields.Update

End With
End Sub

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

What is not happening, is the docvariable in the word doc never gets
populated. I don't get any debug errors, it simply does not populate
the docvariable in my word doc.

Any thoughts?

Thanks for all your help. There is very little flaming here as long as
you follow the rules. I like that.


You need three pieces, and I suspect you have only two of them.

1. The "field" customer_field is a text entry control on the userform. I
assume that works.
2. The document variable customer_var is only a storage location -- by
itself it's invisible. The code you showed is correct, and it works here.
3. The piece that I think you're missing is a DOCVARIABLE field in the body
of the document to display the value of the document variable. Open the
Insert Field dialog, select the DocVariable field type, and enter
customer_var in the "New name" box.

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


  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Erik Witkop Erik Witkop is offline
external usenet poster
 
Posts: 4
Default userform question

On May 15, 12:38*pm, "Jay Freedman" wrote:
Erik Witkop wrote:
Thanks Jay,


But for the life of me I cannot get this working. This is my code.


1. one form with one field. The form name is UserForm1. The field name
is customer_field.
2. one variable in the word doc named 'customer_var'


My code is this:


- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub CommandButton1_Click()
With ActiveDocument


* .Variables("customer_var").Value = customer_field.Text
* .Fields.Update


End With
End Sub


- - - - - - - - - - - - - - - - - - - - - - - - - - - - -


What is not happening, is the docvariable in the word doc never gets
populated. I don't get any debug errors, it simply does not populate
the docvariable in my word doc.


Any thoughts?


Thanks for all your help. There is very little flaming here as long as
you follow the rules. I like that.


You need three pieces, and I suspect you have only two of them.

1. The "field" customer_field is a text entry control on the userform. I
assume that works.
2. The document variable customer_var is only a storage location -- by
itself it's invisible. The code you showed is correct, and it works here.
3. The piece that I think you're missing is a DOCVARIABLE field in the body
of the document to display the value of the document variable. Open the
Insert Field dialog, select the DocVariable field type, and enter
customer_var in the "New name" box.

--
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.- Hide quoted text -

- Show quoted text -


Jay,

I just made a new fresh word doc and added the variable and it works
like a charm. I must have something bad in my original doc.

Thanks for your patience and your help!!!
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
Userform question (selecting name will self complete fields) Darren Ingram Microsoft Word Help 1 April 23rd 08 12:46 PM
Userform Template Bill d Microsoft Word Help 1 February 3rd 07 01:13 PM
Userform Sharpe Microsoft Word Help 1 March 17th 06 07:13 AM
Userform in word SuzieQ Microsoft Word Help 2 December 12th 05 10:42 PM
creating a userform Jill D Microsoft Word Help 8 November 15th 05 08:25 PM


All times are GMT +1. The time now is 02:12 PM.

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"