Results 1 to 9 of 9
  1. #1
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate form fields from external files (XP SP2)

    I know that Word has the ability to link and also embed information based on an external file. What I am trying to do is a little more involved, and I'm hoping that the Word gurus can tell me whether this is worth pursuing or if it is a dead end.

    Here is the scenario:

    A document template for a form created in Word is used for executing test plans, step by step. Users are required to fill out the form online, and save the document.

    During the course of testing, users will be testing with different data sets. The data sets are based on a common protocol, so the formatting will always be the same in the source file, although the data elements may vary widely.

    What I am seeking is a way for end-users (read: non-technical folk) to select an input file, and parse the file's contents to populate certain parts of the form in Word. The less chance the end user has to manipulate the data set as it appears in the document, the better off we will be for their testing. If users are required to manually enter the data, we will not be able to replicate their steps should there be a failure in the test process.

    Using Excel is also an option, although it would require re-creating the test plan in that format - thus, I would like to avoid the additional steps and time involved if at all possible.

    I presume that if this is realistic at all, it will entail some VBA coding. No problems there, but this would be my first foray into this realm of Word in many moons, and I haven't a clue where to begin.

    Hopefully, that was clearer than mud, but if not, I can certainly clarify. Thanks in advance for any ideas you have, gang!
    -Mark

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Populate form fields from external files (XP SP2)

    If your datasets can be opened using ADO (either ODBC or OLEDB), yes, you can programmatically get out whatever you want. If the document is more like print-to-file or HTML, it's messier; you can open the file as a hidden document in Word and parse through it using the usual tools (Find, paragraph counting, etc.). What seems to be the better fit?

    Either way, the user need not be much involved after pointing your procedure to the correct file (the File>Open or Insert>File dialog can be hijacked for this purpose).

    As for inserting the data, if it's a protected form, you can write to the .Result property of a FormField object. If it's not protected, you can insert text at pre-designated bookmarks, or table row-column coordinates. That's the more commonly discussed problem here in the Lounge, so a search might uncover some useful examples, or let us know a bit more about the design of the form and we'll all chime in.

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate form fields from external files (XP S

    Thanks, Jefferson. Sadly it's the messier of the two solutions.

    The environment where this will be needed most desperately is at client locations, and chances are high that they will be testing with flat text files that each contain a single data set. The data sets contain pre-defined delimiters that will not change, ever. For example, the following would be sample data in the file:
    <pre>MSH|^~&|||XMIT_FACIL|XMIT_SYST|200010091149|| ORU|0008444018|P|2.1|654287|
    PID|||1234321||SMITH^BOB^^^^||9877899|M|SMITH^BOB^ ^^^||311 WEST ANY ST
    PV1||I|^RER^||||40007^MORTIS^RIGOR^^^^TITLE||||||| |||||119966111||||||||||||||||||||</pre>

    Each field is delimited by a pipe | symbol, so extracting the pieces I need would be fairly simple. Each section between pipes is a data field, and so on. The form will be protected so that users cannot enter data into any field that I don't want them to mess with.

    As for the form itself, it is a table with five columns, and each row is a step in the test. Very precise, it either passes or fails. It would look like:

    <table border=1><td>Test Step</td><td>Instructions</td><td>Expected Results</td><td>Pass/Fail</td><td>Comments if Fail</td><td>1.</td><td>Open the program</td><td>Program opens</td><td>Pass</td><td>None</td></table>

    My intent is to have certain elements from the sample message pop into defined fields in a few of the test steps. The user would open the form, then point it towards the test message, and automagically the data that is being tested appears in all the right places - no chance for them to screw it up. Given the number of times that users would have to run a test scenario, automation of this would be ideal to cut down on errors and tedium. Thus, if I can write the code to parse out the message as shown in the sample, I can write it into the .result property.
    -Mark

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Populate form fields from external files (XP SP2)

    Could you have a VBE form that populates a list box with the available data set names when it is initialised, then allow the user to select a data set from the drop down list box and define a set of document variables? These document variables could then appear at appropriate places in the document.

    StuartR

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Populate form fields from external files (XP S

    Are the rows/records delimited with CRLF? If so, this should not be so bad. You could read each line using either the FileSystemObject (TextStream.ReadLine) or the old fasioned BASIC file access methods (Line Input), and then auto-parse it into a dynamic string array using Split(string, "|"). Once you have the array, you then can pop the data into your form. Hope this helps. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate form fields from external files (XP S

    A VBE form is not out of the question, but it adds complexity to the situation. What I am hoping to do would not require anything other than a stock installation of Word itself.

    Of course, given the nature of the implementations that I am working with, VBE forms could also be a prerequisite, but that might not fly well with management (with my management, that is!).
    -Mark

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate form fields from external files (XP S

    Yes, I believe the standard delimiter is a CRLF. I will need to double-check the specs for this protocol (HL7, if that helps). I think the split may just work with a little bit of careful attention to the details. My only concern is that I am modifying the data that I intend for the client to test!

    I'll have a poke with this and see where it goes....thanks for the pointer!
    -Mark

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Populate form fields from external files (XP S

    I don't think you will be modifying any data. particularly with Line Input, it is a read-only method and nothing you do is committed back to the file. (Possibly the TextStream object is read-write.) If you have a different delimiter, you can use the TextStream object's ReadAll method, then split twice, once to create an array of records, and then, looping through the array as needed, split on the pipe to get your fields. Fun stuff!

  9. #9
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Populate form fields from external files (XP S

    Well stuart, I stand corrected. I had initially thought that this project was going to touch external end-users. As it turns out, the automation piece that we are discussing here will be used for internal QA before it ever gets to a client. This is a Good Thing, because it allows me a lot more leeway in what I do with the code!

    Stands to reason, looking back - most of the time, we're lucky to get clients to do testing at all, let alone fill out a Word form when they actually do!
    -Mark

Posting Permissions

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