473,387 Members | 1,569 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,387 software developers and data experts.

Putting a prefix on a fieldname

I have an access db with 6 tables. Four of them i want to merge into
one table. Merging them will give me a poor design but will be much
easier to work with a specific app. Performance isn't an issue. Low
usage, not many rows, and being slow is ok.
Before i copy and paste all the rows over, i want to put a prefix on
each field so i know which table they came from. There are a LOT of fields.

Is there a quick way to put a prefix on all (or a selection) of fields
in a table?
Jun 8 '06 #1
5 1663
Public Function NameChangeTest()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set db = CurrentDb
Set tdf = db.TableDefs("MyTable")
For Each fld In tdf.Fields
fld.Name = "MyPrefix_" & fld.Name
Next fld
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

End Function
However, it seems an odd thing to do, to be frank.
Jun 8 '06 #2
Eric wrote:
I have an access db with 6 tables. Four of them i want to merge into
one table. Merging them will give me a poor design but will be much
easier to work with a specific app. Performance isn't an issue. Low
usage, not many rows, and being slow is ok.
Before i copy and paste all the rows over, i want to put a prefix on
each field so i know which table they came from. There are a LOT of fields.

Is there a quick way to put a prefix on all (or a selection) of fields
in a table?


Here I put an extension
Sub TableFieldRename()
Dim dbs As Database
Dim tdf As TableDef
Dim fld As Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs!Table1
For Each fld In tdf.Fields
'append the number 1 to each field name
fld.name = fld.name & "1"
Debug.Print fld.name
Next
Set tdf = Nothing
dbs.Close
Set dbs = Nothing
MsgBox "Done"
End Sub
Jun 8 '06 #3
Rick Wannall wrote:
Public Function NameChangeTest()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set db = CurrentDb
Set tdf = db.TableDefs("MyTable")
For Each fld In tdf.Fields
fld.Name = "MyPrefix_" & fld.Name
Next fld
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing

End Function
However, it seems an odd thing to do, to be frank.

Thank you very much,
I'll try to get that going, but i don't know how it's going to go. I'm
using ADO rather then DAO

I agree. Normally i would never do this. I usually try to keep the db as
highly normalized as possible. For this specific project it would be
Much faster if everything where in the same table. Granted the real
solution would be to fix the code to use mulitple tables, but this
project is long over due. I'll save database normalization for version 2 :)
Jun 8 '06 #4
Use DAO just for the object model during the renaming. Has no effect on
using ADO for your other tasks.
Jun 8 '06 #5
If you have data that you can correlate row by row across tables, why not
use a select query that joins the three separate tables and present that as
your single-table data?

If you just must know which tables the underlying data is in (a highly
suspect proposition) you can even use aliases in the query so that your
tables stay cleaner.

Select t1.Field1 As T1_Field1, t2.Field2 As T2_Field2
From table1 As t1 inner join table2 as t2
on t1.KeyField = t2.KeyField;

Wouldn't that be a faster solution to your current problem, and also leave
your underlying data normalized, assuming that it currently is?
Jun 8 '06 #6

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

Similar topics

1
by: Holger Joukl | last post by:
Hi there, 2 questions regarding build/installation issues: 1. In the python 2.3.3 setup.py script, the detect_modules method of class PyBuildExt contains the following code: 253 if...
4
by: Stuart Palmer | last post by:
Hi everyone, I have a form with '/' in some of the field names, when I pass through to the next page the field name comes back as though it's been htmlencoded, so getting the value out of the...
3
by: Jacques | last post by:
I'm experiencing the following problem The source xml file uses a prefix (wpl:) and look like this (shortened): ----------------------------------------------------------------- <?xml...
25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
1
by: ad | last post by:
Hi, What is the difference between (string)dr and dr.ToString();
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
1
by: Simon | last post by:
Dear reader, The following functions gives me some problems: Mid(,3,2) and Left() and Date(). On one pc it works perfect and on the other one an error message pop's up "Not a valid...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
3
by: xhe | last post by:
I have just upgraded my php version form php4 to php5. and I met this problem, and don't know if you know the solution. My site was written in PHP4, and most parts can be running smoothly in PHP5,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.