PDA

View Full Version : Access the form field data without opening it.



vince.30000
04-01-2012, 04:51 PM
hi Guys,

I have a Word 2003 form. And it is in read only format. I wanna know. Is it possible to access value of form fields of the form without opening it. I want to use VBA for this.

All I am trying to do is, to access the form field data and populate text boxes in my app.

Your help is really appreciated.

fumei
04-01-2012, 08:22 PM
If you mean access the value of the formfield without openung the document, no, I do not know of any way. That fact that it is read-onloy is not an issue. Even if it is read-only you CAN get the value of a formfield opening the file with VBA.

What do you mean by text boxes in my app. By "app" do you mean another document?

vince.30000
04-02-2012, 03:56 AM
Sorry for using the wrong terminology here. I meant a VBA form. So I am developing a VBA form which has couple of text-boxes. And I want only specific fields from the Word Form to populate in the text-boxes. But what you have said above makes things clear to me.

macropod
04-02-2012, 04:14 AM
Technically, you can't obtain anything from a file without opening it. However, if the formfields have bookmarks (usual), and if all you need is to have the values replicated in another Word document, you could achieve that via INCLUDETEXT fields, with no vba at all. See Word's Help file for details.

fumei
04-02-2012, 07:26 PM
Trying to be clear...

You have Document A, and with that document you have a userform - NOT any forms in the document, but a VBA userform that is called with code.

On that userform, you have textboxes. You want to get values from formfields in document B, and put those values into the textboxes on the userform.

Yes? No?

As macropod states, you can get values from bookmarks in a different document using INCLUDETEXT. But you can not use that method to put values into textboxes on a userform.

vince.30000
04-03-2012, 03:39 AM
Well its like this there is a User Form. And I am making a small kind of application using VBA. And it has buttons on it and textboxes . So what I am looking for is when i press the button on that application it will pickup the form open it access the information from the fields that i am looking for and then populate it in textboxes on my application.

I am not sure wether i should call it application.

fumei
04-03-2012, 01:08 PM
You can do that. Have the commandbutton open the file, get the values from the formfields, put those values into your textboxes. Then if you do not need the file with the formfields, close it.

So. How far along are you? Do you have the userform? Dol you know how to use a userform, and controls on it? Do you really want it to happen with a button click, or perhaps when you start up the userform? Here is an example of a userform (in documentA) that whenit is started up, opens an existing document and puts the value of a formfield into a textbox on that userform.Private Sub UserForm_Initialize()
Dim SourceDoc As Document
Set SourceDoc = Documents.Open("c:\blah whatever.doc")
TextBox1.Text = SourceDoc.FormFields("Text1").Result
SourceDoc.Close
Set Sourcedoc = nothing
End Sub

vince.30000
04-03-2012, 03:05 PM
Hi Fumei,

Exactly what I was trying to achieve. Just that I was trying to figure it out my self...hahaha. But then this code snippet is exactly what I had in mind. The thing is since I am kinda new in VBA and to programming, therefore I was thinking of not opening the word file and accessing the values of the form fields. But in your first reply as you suggested there is no way possible to open the file and read the values of it. Thats when the things got clear.

But thanks for your code snippet. I will try to customize it according to my need.

You are a champ mate.. :thumb