Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Want: enter text in one place, different text appear in another.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kempermo@yahoo.com - 26 Mar 2007 16:30 GMT
What I want to do is similar to repeating data, or populating fields,
but I don't want to populate fields with the same data I'm manually
entering.

For example, in a blank I want to enter "teacher," and a couple of
lines down will display "they educate children."  Instead of teacher I
enter "postal worker," and a couple of lines down will display
"delivers the mail."  In Excel I can do this with a simple IF THEN
statement, but I'm lost in word.

I appreciate the help!

Regards,

Mike
Greg Maxey - 26 Mar 2007 16:51 GMT
Mike,

How you do this depends on what constitutes a blank.  If the blank is
just an area in the document that has a bookmark and you want your
dependent data as an IF field result you would do it like this:

Bookmark "Teacher" as Occ

Enter a series of adjacent IF fields:

{IF {Occ}="Teacher""They educate children"}{IF {Occ}="Postal
Worker""They deliver mail"}{IF {Occ}="Lawyer""They rip people off"}

etc.

If you are want to use VBA then you would use a Select Case Statement.

Again the occupation is bookmarked "Occ"

Place a bookmark "JD" where you want the job description to appear

Sub ScratchMacro()
Dim oRng As Word.Range
Dim oBM As Bookmarks
Set oBM = ActiveDocument.Bookmarks
Select Case oBM("Occ").Range.Text
 Case "Teacher"
   Set oRng = oBM("JD").Range
   oRng.Text = "They teach children"
   oBM.Add "JD", oRng
 Case "Postal Worker"
   Set oRng = oBM("JD").Range
   oRng.Text = "They deliver mail"
   oBM.Add "JD", oRng
 Case Else
   'Do nothing
End Select
End Sub

On Mar 26, 11:30 am, kempe...@yahoo.com wrote:
> What I want to do is similar to repeating data, or populating fields,
> but I don't want to populate fields with the same data I'm manually
[quoted text clipped - 11 lines]
>
> Mike
Greg Maxey - 26 Mar 2007 17:23 GMT
Mike,

Considering you are posting in the UserForm group I figure you might
have been looking for some example related to a Userform.  I would
populate a Listbox with the occupations and job decriptions.  Hide the
job decription from display in the userform and input the information
into the document at bookmarks Occ and JD as follows:

Private Sub CommandButton1_Click()
Dim oRng As Word.Range
Dim oBM As Bookmarks
Set oBM = ActiveDocument.Bookmarks
Set oRng = oBM("Occ").Range
oRng.Text = Me.ListBox1.Column(0)
oBM.Add "Occ", oRng
Set oRng = oBM("JD").Range
oRng.Text = Me.ListBox1.Column(1)
oBM.Add "JD", oRng
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim myArray(2, 2) As String
'Load MyArray
myArray(0, 0) = "Teacher"
myArray(1, 0) = "Postal Worker"
myArray(2, 0) = "Lawyer"
myArray(0, 1) = "They teach children"
myArray(1, 1) = "They deliver mail"
myArray(2, 1) = "They rip you off"
'Hide column 2 by setting width to zero
Me.ListBox1.ColumnWidths = "60,0"
'Populate listbox
Me.ListBox1.List = myArray
End Sub

On Mar 26, 11:30 am, kempe...@yahoo.com wrote:
> What I want to do is similar to repeating data, or populating fields,
> but I don't want to populate fields with the same data I'm manually
[quoted text clipped - 11 lines]
>
> Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.