Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 23rd, 2005, 09:20 AM
Registered User
Join Date: May 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open Word Doc from Access - find, find next save

From Access I want to open a word Document. Search for text and then show a window where I can select the text I want to save to my database.
I have code that does this but it always starts at the top of the document. And
Shows the Last lines in the document if the find is not successful.

How can I open Word's Find window , show the document at the point of the find.
and then get the next result of the find?

I have the code that will select the data I want to save.
It's just getting the windows to open and close.
Plus if there is no success in the search I want to display a message.


Any leads to point me in the right direction will help

Also the With WordObj.Selection.Find Now gives me an illegal Operation and Access closes down.
My Code:

On Error GoTo Err_Command3_Click
Dim WordObj As Word.Application
Dim ProposalName As String

' Start Microsoft Word and open the document.
Set WordObj = CreateObject("Word.Application")

DocumentName = "c:\" & Me.Parent.NameIDField & ".doc"

WordObj.Documents.Open DocumentName, , ReadOnly:=True
' start at the first page of the document

WordObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst

' search for the text
" BIHighlight is string
If BIHighlight = "" Then
BIHighlight = Me.BIField
End If
With WordObj.Selection.Find
.Forward = True
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
' .Execute FindText:="MoveMert"
'.Execute FindText:=Me.BIField.SelText
.Execute FindText:=BusinessIssueHighlight

End With

[Responses.Page] = WordObj.Selection.Information(wdActiveEndPageNumbe r)
' get the next nine sentences
With WordObj.Selection
.StartOf Unit:=wdParagraph, Extend:=wdMove
.MoveDown Unit:=wdParagraph, Count:=9, Extend:=wdExtend
End With
Debug.Print WordObj.Selection.Range
Me.ResponseField = WordObj.Selection.Range

' Close and save the document.
'WordObj.ActiveDocument.Close SaveChanges:=wdSaveChanges
' go back to the start
' later try it without these next three lines

With WordObj.Selection
.GoTo What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=4

End With

' Quit Microsoft Word and release the object variable.

WordObj.Quit SaveChanges:=wdDoNotSaveChanges

Set WordObj = Nothing

Exit Sub

MsgBox Err.Description
Resume Exit_Command3_Click
End Sub


Old May 25th, 2005, 11:09 AM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

I would open Word, start recording a macro, manually do the processes that you want to do (Find, move next, etc.) then see what Word recorded as the VB to repeat those actions.

You will need to add your own Selection.<whatever> probably, to manipulate wht you find.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Open A Word Doc... using ASP .net nikks9 ASP.NET 1.0 and 1.1 Professional 8 March 31st, 2015 03:45 AM
Help need to geneate word doc in open office satyakishore Servlets 0 March 16th, 2006 04:14 AM
How to open a .DOC file with MS-Word ? sherbir Servlets 0 July 26th, 2004 02:39 AM
can't find the regionstext.doc mjafferi Dreamweaver (all versions) 3 March 2nd, 2004 04:10 AM
save word doc. damnnono_86 Access 5 October 21st, 2003 10:51 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.