Converting Word To Access

Gill

New member
Local time
Today, 00:04
Joined
Feb 11, 2002
Messages
7
I have a 12 page questionnaire which is in Word 2000 format. I would like to convert this questionnaire to Access 2000 so that I can input date into the questionnaire, without having to retype the whole thing. How can this be done?
Thanks.
 
Gill,

Create a table in Access with the fields you want saved from the questionnaire. Create a blank form, linked to this table.

Copy the text from the word document and paste in into a form.
Select and place the access fields on top of your pasted text.

12 pages is a bit much and the layout on paper may not work well for online data entry, so you may want to redesign the form a bit, but this should work.

Freddy
 
Gill

I have done something perhaps similar to this. The answer you want depends on the format of the questionnaire. The fact that it is in Word is a good start, because you can do some decent (notice I avoided NICE) things using object automation (used to be called ActiveX, but that has a bad name in the security industry now.)

Before we get started, the odds are that you are looking towards some VBA code. Dollars to donuts says the questionnaire's format isn't quite right for a direct import.

Before you start writing, you have some studying to do. I'll tell you where to look. In the Help files for Access, you can look up Objects and Automation. In the Help Files for Word, you can look up the Word2K topics as follows

Contents>>Programming Information>>Microsoft Word Visual Basic

Then browse around inside that section. It will take a while to read and it ain't easy. What you are looking for is an understanding of the Component Object Model as applied to MS Word. Basically, Word publishes the contents of a document to COM as a series of collections. What you will do in Access is use VBA to explore those collections.

Next, you must get into Access, open a general module (a New one if you don't have one already started), and then follow menu path

Tools>>References

In order to make this kind of project work, you must check the references for Word. Office wouldn't hurt either, though you won't use much from it. (If you were going to use spreadsheets, you would also make sure you checked Excel.) Once those checks are in place, the Methods and Objects defined in the Word VBA Help section become exposed for your use.

I'm going to give you some code snippets and comments about what each one does. It will be up to you to work with them.

To open a particular word document from VBA you need

Dim objApp as Object

Set objApp = CreateObject("Word.Application")
objApp.Documents.Open filename, , false, false, false

This opens a specific Word document read-only. Now, if you don't care to actually see the document open, then between the Set objApp line and the .Open line, insert this line

objApp.Visible = false

With me so far? The document is open and invisible. When the rest of your coding is done, don't forget to close the document AND the object. Otherwise you will slowly deplete your system's resources, eventually requiring a reboot. You would get all sorts of oddball messages about 'unable to open another xyz...' where xyz is some form, report, or other object within Access.

Now, the next part depends on how the questionnaire is built.

Once you have an active document, you can see several collections. One of these is the Tables collection. Another is the Paragraphs collection. You can also see Words. You can also see Lists. One of these is going to be helpful. But here is where things get hazy, because this medium does not permit me to give you precise details of everything you will need to know.

Let me narrow it down to a couple of possibilities. The one I use most often, I'll do first. The next most likely, I'll do next. The rest of the possibilities, you're on your own.

If your questionnaire is table-oriented (i.e. Column 1 of a table is the question, column 2 is the answer) then you have a piece of cake. Each table in a document is numbered. So if there is a single table, then the tables collection is what you want.

In this case, declare a variable to be a Word.Row. Then you can do something like this (prefix str means string, lng means long, I'm not going to actually Dim everything...)

For lngRowNum = 1 to ActiveDocument.Tables(1).Rows.Count loop
rowCurrent = ActiveDocument.Tables(1).Rows(lngRowNum)
strAnswer = rowCurrent.Cells(2).Range.Text
{do something with the answer here}
next lngRowNum

If you have more than one table, then you will have a variable for the table number, too.

You could add data to a recordset from the questionnaire based on what you extracted in the loop. (That's what I do in the application where I use this.)


OK, the other possibility is a numbered list of questions where the numbering WAS done with the numbered-list toolbar button.

In that case, you are looking at a collection of lists. If there is only one collection, your data is in

ActiveDocument.Lists(1)

Here, you would iterate based on the value returned from the Lists(n).CountNumberedItems method as the number of entries in the list. You would extract data from a list by stepping through the list as follows (I think, though it gets tricky here)

ActiveDocument.Lists(n).ListParagraphs(m).Paragraph.Range.Text

The above is the text in one of the numbered items of your list.

Now the bad news. If the questionnaire isn't table or list oriented, or if the list is not numbered but is instead BULLETED, then you have to read the paragraphs one at a time.

So there, the collection is

ActiveDocument.Paragraphs(n).Range.Text

But you have to do some gyrations to get the data out. Look up the use of the Selection object because I believe that you need to select text before you can directly extract it from a paragraph.

Good luck on this. It seems like the above is lot to absorb at once - so don't try. Make frequent reference to the help files. Look at what I wrote and then LOOK IT UP in the help files. You might read some of it differently than I do. And don't be afraid to play with it. As long as you open the document read-only, you can't hurt it. So don't be afraid to fall flat on your face a couple of times playing with it.
 
And please note: Freddy's response is correct IF YOU CAN REFORMAT THE QUESTIONNAIRE. If you are stuck with that format then you have to take my approach. It is ALWAYS easier if you can design with the next few steps in mind. And that even applies to the Word document that you will import.
 
I have a different take on this question. I think that this is a one-time conversion effort and you really want to end up with a table that contains a row for each question rather than a form with filled label controls. If this is the case, you would not want to use automation (except as a last resort). If the questions are in a table in the Word document, you can export the table to Excel or cut and paste it into an Access table of the same format.
 
Having read Pat's post, I concur that another factor has to be considered.

If this is a one-time effort, perhaps you would do better to edit or otherwise fiddle with the form to get it into an importable format. My first answer was STRICTLY if you intend to use the form for a large number of data import operations.

In my case, we used the table trick I mentioned on a form that is used to check new servers into a network where C2 security is required. We have 4 or 5 DOZEN fields to be filled in. We have over 300 servers and expect another 60 to 100 THIS YEAR. I have to be able to regenerate the checkin forms on demand, then re-import them later for updated information. So in our case, we use this method often - and over a long term. For me, this was worth the effort of the automation-level import.

But if your effort is a single-shot operation, don't build a new VBA method. Adapt your data to what Access likes and import using a pre-defined method. Definitely.

I didn't catch the overtone of single-shot, but Pat did. Which might well explain our different answers.
 
How do I export a document from Word to Excel?
 
If the Word document contains a table, select the table and paste it into a spreadsheet or a new table in datasheet view. The data will end up in rows and columns that coorespond to those in the original table. If the data is not in a table, it will end up all in one column with paragraphs being the row breaks.
 

Users who are viewing this thread

Back
Top Bottom