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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find and Replace

Status
Not open for further replies.

smith7255

MIS
Apr 11, 2006
21
US
I was wondering if it is possible to have a table with two columns in it, let's call them OldValue and NewValue, find the OldValue in a text file and replace it with the NewValue. Any information on this would be helpful. If it can't be done in Access, are there any other suggestions. I use access a lot, but I don't really script.
 
If the text file can be stored as a string variable, you can use the Replace function.

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.
 
I found a script on a website that has a command to store the entire file as a string variable. It also shows how to do a find and replace. The only that I am not sure of is how to get a table to interact with the file. I have a list of Old values and new values to replace them with. How would I get it to look at that table and go down the list to find and replace each of those in that table?
 
Use a DAO.Recordset to read the table.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I found this script and it appeared to be what I needed. It is giving me any error 13. I've looked it up and don't really know what to do with it. It has to do with the data type. And again, I don't know anything about writing a script. Any ideas on what to do with it?

Private Sub NewUB92()
Dim strFinalDoc As String
Dim docWord As Word.Document
Dim appWord As Word.Application
Dim rstValues As Recordset

Set appWord = New Word.Application
Set docWord = appWord.Documents.Open("c:\ub92.doc")
appWord.Visible = True

**This is where I get an error. There is something wrong with this line and I can't figure out what it is**

Set rstValues = CurrentDb.OpenRecordset("UCRNptNumbers", dbOpenTable)

rstValues.MoveFirst
Do Until rstValues.EOF
With docWord.Content.Find
.Execute findtext:=rstValues!UCRN, _
Replacewith:=Nz(rstValues!ACCT, ""), _
Replace:=wdReplaceAll
End With
rstValues.MoveNext
Loop
rstValues.Close
Set rstValues = Nothing
appWord.ActiveDocument.Save
End Sub
 
Replace this:
Dim rstValues As Recordset
with this (as clealy stated in my post stamped 17 May 07 10:06):
Dim rstValues As DAO.Recordset

You'll have to reference the DAO library.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That worked! thank you very much!

The word doc takes a little while to open and the find and replace begins immediately. How can I get it to wait until the entire file is opened? Or will it eventually catch up?
 
Ok. Although this works turns out I can't use this. I have a text file. This was the only way I knew to open the file. I don't know how to open a text file in notepad and do a find and replace from Access. Can anyone help with that. My problem is that when I open this text file using word it does not save my pagebreaks. Or maybay some knows how I can keep my page breaks. I am running short on time. Is there anyone that may be able to help me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top