473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

VBA/Access Global Search&Replace from LUT

Ok. I need to develop a macro/vba code to do the following.
>I have a database with 30 tables. Theres a NAME field in nearly all of the tables.
I have been given a spreadsheet with two columns. One contains the NAME of every unique record in the database and the second column is contains either the newly correct NAME or its blank.
I need to automate replacing all of the incorrect NAMEs in the database with the correct NAME entry.
There are at least 300 corrections and its expected for this to happen
a lot more in the future.

Therefore id like a nice button that does this all for me.
In my head the method should go something like this:

1. Import spreadsheet into database and use it as a Look Up Table.
2. Record a macro: Open a table, search&replace for (incorrect) NAME
in target table and replaces with (correct) NAME from LUT. Repeat
for every table. Stop Macro.
3. Step into Macro and somehow adapt it to use each record out of LUT
as a variable to begin with and search and replace with.

Sorry that sounds a bit vague. Im a bit of an amateur with Access &
VBA.

Any pointers on how to do this, or snippets would make my life a lot
happier.
Jun 27 '08 #1
6 2202

<si*****************@gmail.comwrote in message
news:21**********************************@c65g2000 hsa.googlegroups.com...
Ok. I need to develop a macro/vba code to do the following.
I have a database with 30 tables. Theres a NAME field in nearly all of
the tables.
>
I have been given a spreadsheet with two columns. One contains the NAME
of every unique record in the database and the second column is contains
either the newly correct NAME or its blank.
>
I need to automate replacing all of the incorrect NAMEs in the database
with the correct NAME entry.
>
There are at least 300 corrections and its expected for this to happen
a lot more in the future.

Therefore id like a nice button that does this all for me.
In my head the method should go something like this:

1. Import spreadsheet into database and use it as a Look Up Table.
2. Record a macro: Open a table, search&replace for (incorrect) NAME
in target table and replaces with (correct) NAME from LUT. Repeat
for every table. Stop Macro.
3. Step into Macro and somehow adapt it to use each record out of LUT
as a variable to begin with and search and replace with.

Sorry that sounds a bit vague. Im a bit of an amateur with Access &
VBA.

Any pointers on how to do this, or snippets would make my life a lot
happier.
You don't need any VBA to do this, assuming your spread sheet is clean.
1) Link to the spread sheet, it will look like a table to Access.
2) Create an update query linking your Access table to the Spread sheet.
Filter out any names that are blank.
3) Run the query whenever the spreadsheet is updated.

PS: Why do you have 30 tables with the same Name information. You should
have 1 table with the names and a key, then reference the key in the other
tables. You can also eliminate the update step by supplying a form linked to
your names table to whoever is updating the names.
Jun 27 '08 #2
I should have better described this in my original thread - apologies
I was trying to simplify it so it would be easier to read/comprehend.

Lets start over.

I have 30 tables that have a field that contains an ID (descriptive
ID, text strings of up to 50 characters).
I too thought I could create an update query but I was wrong -
I tried adding all the tables to a query.
I then joined them all to the LUT which I imported into Access.
(joined on the corresponding ID field)
I then did an update query to replace the values.

However, what I have now realised is that other fields also contain
these ID names, but NOT in the same record.

Basically this is for a mapping project and each record is a river
catchment. The ID is unique to that catchment. However, there is
also a field which is Upstream_ID and Downstream_ID, and these too
need replacing with the corrected names. In fact there are a series
of different fields that have ID Names in them but do not correspond
to the actual ID for that record.

So if I were to do it via code, you could do a find and replace for
all fields in all tables and loop through the LUT feeding the Search
string to be the Original ID, and the replace variable to be the
Corrected ID.

Pretty sure that would be the best way to go about it, but not too
familiar on how to actually implement it.

Please advise.

Jun 27 '08 #3
I should have better described this in my original thread - apologies
I was trying to simplify it so it would be easier to read/comprehend.

Lets start over.

I have 30 tables that have a field that contains an ID (descriptive
ID, text strings of up to 50 characters).
I too thought I could create an update query but I was wrong -
I tried adding all the tables to a query.
I then joined them all to the LUT which I imported into Access.
(joined on the corresponding ID field)
I then did an update query to replace the values.

However, what I have now realised is that other fields also contain
these ID names, but NOT in the same record.

Basically this is for a mapping project and each record is a river
catchment. The ID is unique to that catchment. However, there is
also a field which is Upstream_ID and Downstream_ID, and these too
need replacing with the corrected names. In fact there are a series
of different fields that have ID Names in them but do not correspond
to the actual ID for that record.

So if I were to do it via code, you could do a find and replace for
all fields in all tables and loop through the LUT feeding the Search
string to be the Original ID, and the replace variable to be the
Corrected ID.

Pretty sure that would be the best way to go about it, but not too
familiar on how to actually implement it.

Please advise.

Jun 27 '08 #4

<si*****************@gmail.comwrote in message
news:2f**********************************@x41g2000 hsb.googlegroups.com...
I should have better described this in my original thread - apologies
I was trying to simplify it so it would be easier to read/comprehend.

Lets start over.

I have 30 tables that have a field that contains an ID (descriptive
ID, text strings of up to 50 characters).
You will simplify the problem by only having the ID field in the 30 tables,
use a join table with the ID and Descriptive ID. If any chance the ID can
change, use a AutoNumber primary key in the new join table to be used to
link your 30 tables. This Key would never be displayed to a user, changes to
the ID would only happen to 1 record.
I too thought I could create an update query but I was wrong -
I tried adding all the tables to a query.
With your structure you will need 30 update queries, one for each table. The
only VBA required would be to run each of the 30 queries. This of would need
to be run inside a transaction so if one failed no changes would be saved.

I then joined them all to the LUT which I imported into Access.
(joined on the corresponding ID field)
I then did an update query to replace the values.

However, what I have now realised is that other fields also contain
these ID names, but NOT in the same record.

Basically this is for a mapping project and each record is a river
catchment. The ID is unique to that catchment. However, there is
also a field which is Upstream_ID and Downstream_ID, and these too
need replacing with the corrected names. In fact there are a series
of different fields that have ID Names in them but do not correspond
to the actual ID for that record.

So if I were to do it via code, you could do a find and replace for
all fields in all tables and loop through the LUT feeding the Search
string to be the Original ID, and the replace variable to be the
Corrected ID.
There is no find and replace feature for data in multiple tables. You could
code some VBA to open 31 record sets to do the lookup and edit, but that can
be very slow running and pron to error.
>
Pretty sure that would be the best way to go about it, but not too
familiar on how to actually implement it.

Please advise.
What are the 30 tables? Your current structure allows one upstream and one
downstream? What happens if a river has 2 upstream; add a 2nd upstream ID
and Name then edit your update loop? Lookup normalization, it will help you
in the long run.
Jun 27 '08 #5
I have no control over the database structure - its a clients and I
cant really mess with it, I just need to be able to
Find and replace data across multiple tables.

I thought id be able to do this with one update query, but like you
mention...
>With your structure you will need 30 update queries, one for each table. The
only VBA required would be to run each of the 30 queries. This of would need
to be run inside a transaction so if one failed no changes would be saved.
Didnt really fancy setting up loads of queries - Because each table
has three or so fields within it that need checking for old ID values
and replacing with new ID values. Therefore each table itself may
need 3 separate update queries, 30 table = lots of time consuming
queries. Id like to leave this as a last resort.
There is no find and replace feature for data in multiple tables. You could
code some VBA to open 31 record sets to do the lookup and edit, but that can
be very slow running and pron to error.
I have found snippet of code that finds and replaces, but I need to
automate
Opening a target table, opening the Look Up Table, loop through the
Look Up Table to feed into the S&R function the Old And New IDs, then
move onto the next record until its finished. Then move onto the next
table.

I imagine this may take awhile but the tables contain around 7000
records each, so memory shouldnt be an issue and not fussed about time
as long as it works.
Manually, if I select everything in a table and S&R, it seems to be
pretty quick and cant imagine there being any errors.

What are the 30 tables? Your current structure allows one upstream and one
downstream? What happens if a river has 2 upstream; add a 2nd upstream ID
and Name then edit your update loop? Lookup normalization, it will help you
in the long run.
Good points - strengthens the case to come up with some VBA code to
S&R?

Thanks for your help so far, please dont leave me!
Jun 27 '08 #6

<si*****************@gmail.comwrote in message
news:2b**********************************@y38g2000 hsy.googlegroups.com...
I have no control over the database structure - its a clients and I
cant really mess with it, I just need to be able to
Find and replace data across multiple tables.

I thought id be able to do this with one update query, but like you
mention...
With your structure you will need 30 update queries, one for each table.
The
only VBA required would be to run each of the 30 queries. This of would
need
to be run inside a transaction so if one failed no changes would be
saved.
>
Didnt really fancy setting up loads of queries - Because each table
has three or so fields within it that need checking for old ID values
and replacing with new ID values. Therefore each table itself may
need 3 separate update queries, 30 table = lots of time consuming
queries. Id like to leave this as a last resort.
There is no find and replace feature for data in multiple tables. You
could
code some VBA to open 31 record sets to do the lookup and edit, but that
can
be very slow running and pron to error.

I have found snippet of code that finds and replaces, but I need to
automate
Opening a target table, opening the Look Up Table, loop through the
Look Up Table to feed into the S&R function the Old And New IDs, then
move onto the next record until its finished. Then move onto the next
table.

I imagine this may take awhile but the tables contain around 7000
records each, so memory shouldnt be an issue and not fussed about time
as long as it works.
Manually, if I select everything in a table and S&R, it seems to be
pretty quick and cant imagine there being any errors.

What are the 30 tables? Your current structure allows one upstream and
one
downstream? What happens if a river has 2 upstream; add a 2nd upstream
ID
and Name then edit your update loop? Lookup normalization, it will help
you
in the long run.

Good points - strengthens the case to come up with some VBA code to
S&R?

Thanks for your help so far, please dont leave me!
Queries would be the quickest and safest way to do this. Use VBA and
transactions to run the queries to prevent only some of the tables updating.
If you don't want to store the queries, you could build them in code as part
of your VBA. If each table has 3 name field to update you will need 90
queries, with 7000 records per table or 630,000 possible updates so memory
could be an issue.

You could use recordsets to update 1 table at a time but that would be
harder then queries and much slower.

Add some code to verify the update table before you start updating your
data.

I hope the client understands the structure will cause inconsistent data.
UMO the time you spend doing this project and they spend fixing data would
be better spent fixing the structure.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Zenobia | last post by:
Hello I want a search & replace text in source code for several files in several directories. It would seem that both Dreamweaver MX 6 and GoLive 6 offer this feature but not for .aspx file...
3
by: tchurm | last post by:
Hi Pythonistas, Here's my problem: I'm using a version of MOOX Firefox (http://moox.ws/tech/mozilla/) that's been modified to run completely from a USB Stick. It works fine, except when I...
1
by: Tomomichi Amano | last post by:
Could some one tell me how I can seach and replace only one word in a textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to replace ALL , but I don't know how to REPLACE one,...
1
by: Tomomichi Amano | last post by:
Hello. I want to make replace & search functions in my text editor. Thanks to the kind people here at the newsgroup, I was able to make the function. But I was not able to understand how to...
2
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder...
4
by: Jon | last post by:
Hi, I have an arrayList that holds an ArrayObject with (Qty & ItemCode). e.g. arrayList.Add(New ArrayObject(Qty, ItemCode) However, I want to search the arrayList and check if the ItemCode...
6
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! #...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
5
by: simon.robin.jackson | last post by:
This requires a table called tblReplace with two text fields, old and new. Code: On Error Resume Next Dim db As DAO.Database Dim td As DAO.TableDef Dim f As DAO.Field Set db = CurrentDb
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.