473,749 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: VBA/Access Global Search&Replace from LUT

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
For Each td In db.TableDefs
If td.Name <"tblReplace " And Left(td.Name, 4) <"msys" Then
For Each f In td.Fields
SQL = "UPDATE [" & td.Name & "] INNER JOIN tblReplace ON
[" & _
td.Name & "].[" & f.Name & "] = tblReplace.old SET ["
& _
td.Name & "].[" & f.Name & "] = [tblReplace]![new];"
db.Execute SQL
Select Case Err.Number
Case 0
Case 3615: Err.Clear
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Exit Sub
End Select
Next
End If
Next
Anyone disagree?
Jun 27 '08 #1
5 1619

<si************ *****@gmail.com wrote in message
news:25******** *************** ***********@r66 g2000hsg.google groups.com...
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
For Each td In db.TableDefs
If td.Name <"tblReplace " And Left(td.Name, 4) <"msys" Then
For Each f In td.Fields
SQL = "UPDATE [" & td.Name & "] INNER JOIN tblReplace ON
[" & _
td.Name & "].[" & f.Name & "] = tblReplace.old SET ["
& _
td.Name & "].[" & f.Name & "] = [tblReplace]![new];"
db.Execute SQL
Select Case Err.Number
Case 0
Case 3615: Err.Clear
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Exit Sub
End Select
Next
End If
Next
Anyone disagree?
You stated in the OP that the Excel sheet contains records where the new
name is blank. Assuming those records should not be updated, modify your
query to filter them out.

It looks like you are linking every field in every table to tblReplace and
updating any matching record. You will likely get errors on every run for
every table, so you will need to be at the computer clicking OK to each
message. Understand that you as you update the data is inconsistent until
all 30 tables are done and you can't use transactions because of the errors.
Try it on a test copy and see how long it takes to run and how your data
looks afterwards.

I would think running it in Access with linked tables would be better, but
it can be done in Excel.
Jun 27 '08 #2
Ron has, perhaps, a good deal more patience than many here.

Your client has a flawed database design that makes it difficult to
accomplish a relatively simple task. In fact, it is the type of Access
database that experienced people here class as "committing spreadsheet" --
spreadsheets are very flexible for small amounts of data and manual
manipulations; databases are for structuring your data and automating
handling and manipulations -- an Access DB is not just a "bigger Excel
spreadsheet".

Rather than saying "I have no control, only have to do what is requested,"
you have an opportunity to "be a hero"; personally, I think you have an
obligation to the client to carefully explain in simple terms how the flawed
design will, sooner or later (and probably sooner, like before this project
is complete) "rise up to bite them in the tender places." You can likely
make a good case that restructuring and normalizing the data, then making
the changes, will result in less time/effort/cost that making the changes to
what they have.

I, for one, haven't the patience to review code that encourages persisting
an improperly structured database. I suspect others here will take a
similar view: "fix your database structure first, then deal with the
changes, which in a well-structured database."

In a properly structured database, all those fields in all those tables
would contain a "foreign key", the ID field of a names table, those foreign
key fields would not need to be changed, only the text of the names in the
names table, and, lo, the proper names would appear whereever the foreign
key was used to join to the names table (which should be everywhere you need
to display the name). Not "magic," just proper relational design.

Larry Linson
Microsoft Office Access MVP

<si************ *****@gmail.com wrote in message
news:25******** *************** ***********@r66 g2000hsg.google groups.com...
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
For Each td In db.TableDefs
If td.Name <"tblReplace " And Left(td.Name, 4) <"msys" Then
For Each f In td.Fields
SQL = "UPDATE [" & td.Name & "] INNER JOIN tblReplace ON
[" & _
td.Name & "].[" & f.Name & "] = tblReplace.old SET ["
& _
td.Name & "].[" & f.Name & "] = [tblReplace]![new];"
db.Execute SQL
Select Case Err.Number
Case 0
Case 3615: Err.Clear
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Exit Sub
End Select
Next
End If
Next
Anyone disagree?

Jun 27 '08 #3

"Larry Linson" <bo*****@localh ost.notwrote in message
news:hRW%j.24$B Y1.18@trnddc06. ..
Ron has, perhaps, a good deal more patience than many here.
My patience is more self preservation. How many members have had to defend
Access to clients, co-workers, IT consultants, who say Access is junk or a
toy because of databases like the proceeding.
Jun 27 '08 #4
Ron & Larry - good comments, taken on board and I am already thinking
on how to best re-structure the data.

However, this is not a simple Access Database. Its a GeoDatabase
(created from ArcMAP software) and the main front end for the data is
within the ArcMAP software. Bit hard to explain, but it makes
database design a bit limited as there are already a number of
datasets that have been created around this existing database design.

I might post a separate thread if I can come up with a plan/get the
plan approved.

Thanks loads everyone. The script I posted earlier did work for my
short-term requirements, I understand that errors could have crept in,
but I fiddled it to look at only the fields required and if there was
an error, to skip over it.
Jun 27 '08 #5
There are always exceptions that have to be dealt with. It's really helpful
if we know enough detail about the situation to avoid long side-tracks.
Good luck.

Larry

<si************ *****@gmail.com wrote in message
news:88******** *************** ***********@p25 g2000hsf.google groups.com...
Ron & Larry - good comments, taken on board and I am already thinking
on how to best re-structure the data.

However, this is not a simple Access Database. Its a GeoDatabase
(created from ArcMAP software) and the main front end for the data is
within the ArcMAP software. Bit hard to explain, but it makes
database design a bit limited as there are already a number of
datasets that have been created around this existing database design.

I might post a separate thread if I can come up with a plan/get the
plan approved.

Thanks loads everyone. The script I posted earlier did work for my
short-term requirements, I understand that errors could have crept in,
but I fiddled it to look at only the fields required and if there was
an error, to skip over it.

Jun 27 '08 #6

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

Similar topics

1
3292
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 types. Is there a hack that sets the configuration files for one of these programs and fools the program into allowing the global search and replace?
3
3362
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 install or uninstall an extension, in which case I then have to physically edit the compreg.dat file in my profile directory, replacing all instances of Absolute Path links to relative ones. (And, yes, I have filed a Bugzilla report.) For example,...
1
1966
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, and how to SEARCH one and select that point. Thank in advance
1
1680
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 REPLACE the next word (the nearest word from the cursor; not REPLACE ALL, but replace only one word) and SEARCH the next word. COuld some one help me? Thanks in advance.
2
1388
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 if there is a better and faster way to do it. To make it clear: The search&replace must be done within a programm not in the Framework or editor.
6
2675
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! # Search & Replace file = open("text.txt", "r") text = file.read()
2
5097
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, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
6
2233
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. 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:
0
256
by: simon.robin.jackson | last post by:
I can open the tables into Excel no problem and rekon i could macro/ vba it in excel a bit easier. However, this is a copy of the data I think? not the actual source data from the .mdb. Is there a way to edit access data in excel and save it without having to import/export?
0
8997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.