Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Developer Toolkits / September 2005

Tip: Looking for answers? Try searching our database.

Find and Replace text within a field - automate process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
whats up skip - 19 Sep 2005 02:20 GMT
I am trying to find and replace many different text variables within one text
field in a MS Access data base.
I do have a table of variables and what I want to replace them with, however
I cannot workout how to automate this process. My knowledge of VB, and SQL is
very poor.

I can get this simple command to work, but I cannot get it work through the
whole table of variables that need to be replaced. The issue here is that
variable only makes up part of the text in the field "HotelName".

UPDATE HotelData SET HotelData.HotelName =
Replace([HotelData]![HotelName],"Melbourne","Melb");

I tried to added to this but had no luck. Such as

UPDATE HotelData SET HotelData.HotelName =
Replace([HotelData]![HotelName],"Melbourne","Melb");UPDATE HotelData SET
HotelData.HotelName = Replace([HotelData]![HotelName],"Sydney","Syd");

This obviously creates an error, but I could not workout the correct
structure.
Alex Dybenko - 19 Sep 2005 06:00 GMT
Hi,
i think you can just run your SQL statement severeal times, for each replace
you need

so you open a recordset based on your table of variables, loop through it
and run update SQL for each record

Signature

Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

>I am trying to find and replace many different text variables within one
>text
[quoted text clipped - 21 lines]
> This obviously creates an error, but I could not workout the correct
> structure.
whats up skip - 19 Sep 2005 07:04 GMT
Are you able to make a suggestion of the structure of this kind of loop?

> Hi,
> i think you can just run your SQL statement severeal times, for each replace
[quoted text clipped - 28 lines]
> > This obviously creates an error, but I could not workout the correct
> > structure.
Chris Mills - 19 Sep 2005 07:32 GMT
I took the trouble to test your first SQL, and it worked fine for me (after I
changed it to tables I have!). Some of the syntax (. vs !) seemed a bit
suspect but never mind.

Of course, you can't concatenate SQL statements the way that you suggested
(after the ending semicolon).

Then I tried (using Query Wizard, ie the "intelligent screen") to put two
replacements in, and that seemed OK too.

Then I got a query compile error, and since I'm not working for you I gave up.
<g>

I assume you're aware that you must SAVE an update query before running it. If
you run it during design, it will just act like a SELECT query.

As to loops, or how I'd really do it, I guess I'd do it in VBA code (not
really a loop)
Q="UPDATE blah blah"
db.execute(Q)
Q="Update this-or-that"
db.execute(Q)

Unless the things to update are retrieved from a table or array or something,
it's not necessarily really a "loop". Just a bunch of sequential updates,
crude perhaps but effective. You could (at a pinch) run a bunch of update
queries from a macro, I suppose.

Chris

> Are you able to make a suggestion of the structure of this kind of loop?
>
[quoted text clipped - 30 lines]
> > > This obviously creates an error, but I could not workout the correct
> > > structure.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.