Export form data to other form in Word

Q

QAadmin

Hi everybody,
Is there a way I can import data from one Word form into another Word form?
I have a form where there is a Yes/No checkbox, and when the user checks Yes,
another form opens up. I have a code that actually does open another form,
but my problem is how to actually "link" the two, that is, the second form
should have some identification as to which form actually invoked it.
Thanks in advance.
 
G

Graham Mayor

Assuming a protected form with form fields the following macro will open the
other document - here called D:\My Documents\Test\Versions\Odd\Doc2.doc when
the check box Check1 is checked and writes the content of the text field
Text1 in the source document into the form field Text2 in the opened
document. Change (and add) the field and document names to suit your
requirements

Sub CopyDataToAnotherDoc()
Dim Source As Document
Dim Target As Document
Dim sField1 As String

Set Source = ActiveDocument
If Source.FormFields("Check1").CheckBox.Value = True Then
Documents.Open FileName:="D:\My Documents\Test\Versions\Odd\Doc2.doc"
Set Target = ActiveDocument
sField1 = Source.FormFields("Text1").Result
Target.FormFields("Text1").Result = sField1
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Q

QAadmin

Thank you very much Graham. I've made my adjustments, and the code worked
great. The only question I have is how to make that second form stay on top
of the first form? when I check Yes, the other forms opens up with the info
that I need in it, but it's behind the original invoking form. It's probably
a one or two lines of code, but I am not sure what...
Thank you again.
 
G

Graham Mayor

Add
Target.Activate
immediately before End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Q

QAadmin

Actually, I used this statement prior to posting my question, and it didn't
do the trick. But what I did was added a "Source.close" right before the
"Target.Activate" statement, and it worked I don't know how. Both files
actually stay open, with the target form on top. But I appreciate all your
input. Thanks a lot for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top