Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access and Word VBA Finding Item in RecordSet

Status
Not open for further replies.

BeckyMc

Technical User
Jun 19, 2001
51
0
0
US
I'm not sure I'm thinking straight about this one. I'm trying to open a simple query, pull an item, look for it on a Word file and then bold it if it's found. If not move to the next item. I'm not sure I've done the best thing here as I can bold the first instance but no subsequent instances. It is looping through my recordset and finding the items. It's only bolding one instance of the items though. Suggestions?

set db = currentdb
set rst = db.openrecordset ("Q_Violation_Codegroup",dbopendynaset)

rst.movefirst
if not (rst.bof and rst.eof) then

myfindcode = rst!codegroupwordver

wordobj.selection.homekey unit:=wdstory

with wordobj.selection.find
.forward = true
.clearformatting
.matchwholeword = true
.matchcase = false
.wrap = wdfindcontinue
.execute findtext=myfindcode
.forward = true
end with
wordobj.selection.font.bold = true

rst.movenext

loop

end if
 
Sure°!

You have a "loop" but you have no "do".

Plus: your loop is after the ".MoveNext" And I assume your "wordobj" is properly swt? Cause it totally isn't in this code...

Plus: why use selection at all?
Try something along this line:
Code:
[red][s]wordobj.selection.homekey unit:=wdstory[/s][/red]
Do While not rst.EOF
With wordobj.ActiveDocument.Range.Find
 .MatchCase=True
 .yaddayadda...
 .Text=rst!codegroupwordver
 .Replacement.Text=""
 .Replacement.Font.Bold=True
 .Execute Replace=wdReplaceAll
End With

rst.MoveNext
Loop

:)

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I did have a do but I forgot to type it but I never think about search and replace for formatting. I always think about searching and replace for text so thanks a ton! That was perfect!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top