Consulting

Results 1 to 10 of 10

Thread: Populate Text Form Fields from excel worksheet

  1. #1
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location

    Populate Text Form Fields from excel worksheet

    Hello,

    I have a Word template locked for filling in forms and a spreadsheet with data that corresponds to each field. What I want to happen is for when the user enters a word/string in the first text form field that matches what is in spreadsheet (eg column B) it will fill in the remaining text fields from that row (probably on the Run macro on exit command) else if the word/string cannot be found it will return an error message.

    I can upload example template & spreadsheet if needed.

    Thanks

    fra

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Is there a reason for not doing this with a mailmerge, where you can just select the desired record and have Word extract all the required data from Excel?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    See the thread - http://www.vbaexpress.com/forum/show...-from-Word-VBA which shows how to write the worksheet to an array, which you can interrogate to find the record you want and consequently the rest of the information in that row.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location
    Hi Paul, thought about that but decided it was'nt practical.

    Graham I will give that a try and reply later today with result.

    Thanks
    fra

  5. #5
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location
    Hi Graham,

    The first text field in Word would have to act like a search function which finds an exact match in the spreadsheet then fill in the remaining fields in Word based off that row.

    fra

  6. #6
    That should be fairly straightforward, but I would need to see the document.
    Can you post the document and the worksheet as you indicated you would in your first message.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  7. #7
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location
    Thanks Graham, please see attached.

    fra
    Attached Files Attached Files

  8. #8
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location
    Sorry just realised one of the columns was missing in worksheet
    Attached Files Attached Files

  9. #9
    Hmmm. While what you propose is simple enough, it looks as though you are sending this form to the client for completion. The client is almost certainly not going to have access to your database and so will not be able to fill the form using data from it. You will need to complete that part of the data before sending out the forms.

    What you need here is a combination of mail merge and form fields and Word on its own does not do that. My suggestion would be http://www.gmayor.com/ManyToOne.htm which will combine protected forms with mail merge fields. You would replace the formfields with merge fields in the first part of the document and complete the merge either to separate documents or to e-mail.

    See also http://www.gmayor.com/ExtractDataFromForms.htm which should help when the forms are returned.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  10. #10
    VBAX Regular
    Joined
    Sep 2017
    Posts
    25
    Location
    Many thanks Graham thats exactly what I'm after - I will mark this as solved. Just out of interest what would the code be or could you provide a link if they were internal clients who would have access to the network drive the worksheet is stored on?

    fra

Posting Permissions

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