Solved

extract words from a document and store in a database field

Posted on 2013-11-06
3
597 Views
Last Modified: 2013-11-08
I would like to store the words from a word document, .doc or .docx, in a database field in order to speed up searches.

I have used the textstream command in access 10 vba to convert my text documents but wondered about the best way to extract the words from a Word document.

I thought about opening the .doc and saving it as a .txt and then using the textstream command to extract the data but wondered if there was a quicker, cleaner method of doing this?
0
Comment
Question by:Nemetona
3 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 300 total points
Comment Utility
I would do the searching in Word, which has superior methods for finding text strings.  Make a Word macro to do the searching, and store the found words in your Access database.  You can use code like the following (from a Word VBA procedure) to work with an Access database.

Public Sub OpenAnotherDatabase()
'Created by Helen Feddema 14-Feb-2010
'Last modified by Helen Feddema 14-Feb-2010

   Dim appAccess As New Access.Application
   Dim strDBNameAndPath As String
   Dim dbs As DAO.Database
   Dim rst As DAO.Recordset
   Dim dbe As DAO.DBEngine
   
   'Change to your db name and path
   strDBNameAndPath = "G:\Documents\Access 2002-2003 Databases\General.mdb"
   appAccess.Visible = True
   appAccess.OpenCurrentDatabase filepath:=strDBNameAndPath, _
      exclusive:=False
      
   'Run a procedure
   'appAccess.Run "PrintOrdersReport"
   
   'Run a macro
   'appAccess.DoCmd.RunMacro "mcrPrintOrdersReport"
   
   'Run an action query
   'appAccess.DoCmd.OpenQuery "qryDeleteSomeOrders"
   
   'Run SQL code
   strSQL = "DELETE tblOrders.ShippedDate FROM tblOrders WHERE ShippedDate = #8/4/1994#;"
   Debug.Print "SQL string: " & strSQL
   'appAccess.DoCmd.RunSQL strSQL
   
   'Iterate through a recordset
   Set dbe = appAccess.DBEngine
   Set dbs = dbe.OpenDatabase(strDBNameAndPath)
    
   Set rst = dbs.OpenRecordset("tblCategories")
   Do Until rst.EOF
      Debug.Print rst![CategoryName]
      rst.MoveNext
   Loop
   rst.Close
    
   Set dbs = Nothing
   Set appAccess = Nothing
   
End Sub

Open in new window

0
 
LVL 14

Assisted Solution

by:DrTribos
DrTribos earned 200 total points
Comment Utility
I'm not sure about textstream, never used it... you could perhaps load all the words from your document into a scripting dictionary and then move them straight into your database.  

I am assuming you will not be searching for phrases, just words.  You could exclude duplicates...  and for that mater also exclude words shorter than 4 characters etc...
0
 

Author Comment

by:Nemetona
Comment Utility
Thanks for your responses, I obviously did not explain my problem to well and have since found a work around using saveas2
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now