Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| 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 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
  #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.

Thanks

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"
'Stop

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

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

'Stop
' search for the text
" BIHighlight is string
If BIHighlight = "" Then
BIHighlight = Me.BIField
Else
End If
With WordObj.Selection.Find
.Forward = True
.ClearFormatting
.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)
Me.PageField.Requery
'Stop
' 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

'Stop
' 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_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub

Don

  #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
Default

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.