Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2005, 09:20 AM
Registered User
Join Date: May 2005
Location: Manchester, CT, USA.
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


Reply With Quote
  #2 (permalink)  
Old May 25th, 2005, 11:09 AM
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
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.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:11 AM.

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