Results 1 to 8 of 8
  1. #1
    diggerj
    Guest

    UserForm (Word 2000)

    I am standardizing a form to be used at several different locations. I need to be able to enter a certain substance (i.e., zinc, copper, aluminum) and the verbage that coincides with that substance will automatically be input into the document in another area. Can this be done and would a UserForm be the way to go?
    Thanks in Advance <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: UserForm (Word 2000)

    Hi,

    No doubt this can be done, but determining the best method for doing it requires some more detail - who are the users, and what is the purpose of the form and document? what input is required from them? - do you need to make this form available only when a new document is first created or do you need to make it possible to insert additional information into existing documents?

    If you can flesh out as much as possible what you need to do, I'm sure someone here will be able to come up with a good idea.

    Gary

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm (Word 2000)

    I've done this in two ways. Both ways have involved form fields, associated with a macro which is triggered on entry to, or on exit from, the form field.

    The first way involves a dropdown form field. When the user selects an option, and transfers control to the next form field, the "on exit" macro form the first form field (the dropdown) is triggered. This macro fills in, in the other part of the form, the extra verbage.

    The other way involves a form field which is triggered "on entry"- when the user enters that form field. This macro pops up a userform, listing all the options, and each option shows all the extra verbage. This options is suitable when the choice is not so clear cut, and helps the user to choose based on more than just a simple pick.

    My aplogies if I haven't explained well. Feel free to ask, and someone will be able to help.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm (Word 2000)

    diggerj,

    I'm responding to a private message. I don't encourage these- I prefer to keep responses on the forum, so that:
    1. They can be of use to others
    2. Other people can correct, expand, and help.
    3. Speaking for myself- as a Mod, I spend lots of time just keeping track of the forums. I don't have a lot of time to answer- and I certainly do not have anywhere near the experience of many on the board.

    But that's cool. This time anyway <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Your message was:
    <hr>I am not very good with macros and I'm in a real jam to figure this out. Hoping you can help.

    How would I set this up? I am looking at possible over 100 different words that will need to be automatically put into a document, all depending on the original word. Here's a small example of what I need on a large scale.

    Perhaps the key word is aluminum. I would need the "on exit" macro read from somewhere the word aluminum then fill in into another part of the original document the description of aluminum. Or possible copper is the key word then I would need the "on exit" macro to pull the description of copper. This list of substances and their descriptions could possibly be quite lengthy. My question is 2 part

    1. Where would I store ALL the information

    2. How do I set up this type of "on exit" macro; like I said I am not too good with this type of stuff but I know it can be done. If you could please give me step by step instructions, it would really be nice. Remember you are dealing with an old Word user just not this indepth.<hr>
    The easiest (but least flexible) way to do this is the store all the wording in the macro itself:<pre>Sub FillElement()

    dim strText as String
    strText = ""
    Select Case ActiveDocument.Formfields("ElementCode").Result
    Case "zinc"
    strText = "Zinc is used in batteries"
    Case "copper"
    strText = "Copper is a brown metal"
    end Select

    Activedocument.Formfields("Description").Result = strText
    end sub</pre>

    There are posts already to show where to put a macro. Assuming the macro has been created, here's how to set up the document ready for it:

    .In the document. add two text form fields (First, show the forms toolbar- View, Toolbars, Forms). Position the cursor in your document. Click on the one with "ab" to insert a formfield. Bow double click on the newly created form field. Change to "Bookmark" name to "ElementCode". On the "Run macro on exit" field, select "FillElement" from the list. It should appear if it has been entered.

    Position the cursor where you want the result text to go. Name that one "Description".

    Then "Tools","Protect Document","Forms".

    If you enter "zinc" or "copper" in the first field, something should appear in the second.

    Some ways to make this nicer:
    .Check for lower case values of what's entered in the form field
    .Use autotext to populate the entries- it will be easier to maintain
    .Or even use a database which you can interrogate. Much more complex, but it can be maintained outside your Word environment.

    If you enter "copper" or "zinc" into the first field, the description will appear in the second field.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    diggerj
    Guest

    Re: UserForm (Word 2000)

    Thanks a million, it worked perfectly. But of course I need to know one more thing. I need to be able to fill several lines this way. One text box would have iron and its verbage, and on the next line I would need to enter maybe Copper and get it's verbage. How do I do this on and on, line after line each time with a different substance and it's definition?

  6. #6
    diggerj
    Guest

    Re: UserForm (Word 2000)

    Along these same line,what would the macro be so that I could extract just certain information from either an Excel spreadsheet or Access database? If I just wanted to manually input an element into the Word document and the macro would pull the correct information from the database/spreadsheet that pertained only to that certain element?

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm (Word 2000)

    Diggerj,

    Sorry- I had forgotten about your question. It's probably too late now- but here goes anyway.

    In order to put verbage into a number of different places depending on which form field was sleected, I'd do something like the following. I'd have this routine in the "On Exit" for every form field you wanted expanded.

    My way of determining which form field is sleected is kludgy- I suspect there's a better way. <pre>Option Explicit

    Sub FillElement()

    Dim ff As FormField
    Dim strControl As String

    'Check which form field contains the selection
    For Each ff In ActiveDocument.FormFields
    If Selection.Start > ff.Range.Start And Selection.Start < ff.Range.End Then
    strControl = ff.Name
    Exit For
    End If
    Next

    'Create the verbage
    Dim strText As String
    strText = ""
    Select Case ActiveDocument.FormFields("ElementCode").Result
    Case "zinc"
    strText = "Zinc is used in batteries"
    Case "copper"
    strText = "Copper is a brown metal"
    End Select

    ' Put the verbage into the appropraie destination form field
    Select Case strControl
    Case "Code1"
    ActiveDocument.FormFields("Description1").Result = strText
    Case "Code2"
    ActiveDocument.FormFields("Description2").Result = strText
    End If
    End Sub</pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: UserForm (Word 2000)

    Pulling the information from Excel should be pretty straightforward, getting it from Access a bit more complicated. Sorry I don't have experience with doing either, so can't provide you with any readymade code.

    If your coding background is limited, you're best off starting out with the approach of storing the data in the code, as Geoff has suggested. That way is the easiest to get something usable set up. Getting that up and running then gives you the luxury of being able to take the time to get up to speed on how to pull the data from other sources, be they text files, Excel or Access.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •