Hi, Alex.
If someone helps me by giving me code for this, can they also help me, with
having the code apply itself to the whole recordset....
250,000 records... very
time consuming....
Of course. Using SQL, one can do this very easily and fairly quickly, even
with 250,000 records, as long as:
1.) Every record has the requisite 19 characters in the "Compound" field in
the order that you described; and
2.) Your table doesn't already have fields matching the new field names;
and
3.) Your table isn't close to exceeding the maximum 255 fields, or the
maximum record length, or the 1 GB size limitations; and
4.) The database file itself isn't close to meeting the 2 GB size
limitation.
Unlikely circumstances, but I thought I'd let you know what the show
stoppers are.
First, back up your database in case something goes wrong. Next, create a
new query and open the SQL View pane. Copy the following SQL statement and
paste it into the SQL View pane:
ALTER TABLE tblCensus
ADD COLUMN NameID Text (6),
DOB Date,
Sex Text (1),
CountyNumber Long,
IDNumber Long;
You'll need to change the table name, tblCensus, to whatever table name you
are using. I changed your "Name" field because "Name" is a reserved key
word, and should not be used in identifiers, such as table names, field
names, variables, et cetera. Save the query with a name such as
qryAddTblCensusColumns, but use your own table's name. While in the SQL
View pane, run the query. This query just added the new fields to your
table.
Next, create a new query and open the SQL View pane. Copy the following SQL
statement and paste it into the SQL View pane:
UPDATE tblCensus
SET NameID = MID(Compound, 1, 6),
DOB = CDate(MID(Compound, 9, 2) & "/" & MID(Compound, 11, 2) & "/" &
MID(Compound, 7, 2)),
CountyNumber = MID(Compound, 13, 2),
Sex = MID(Compound, 15, 1),
IDNumber = MID(Compound, 16, 3);
Again, you'll need to change the table name, tblCensus, to whatever table
name you are using. Save the query with a name such as
qryUpdTblCensusColumns, but use your own table's name. While in the SQL
View pane, run the query. This query just updated the new fields in your
table with the parsed data from the Compound field.
Next, create a new query and open the SQL View pane. Copy the following SQL
statement and paste it into the SQL View pane:
ALTER TABLE tblCensus
DROP COLUMN Compound;
Again, you'll need to change the table name, tblCensus, to whatever table
name you are using. Save the query with a name such as
qryDropTblCensusColumn. Don't run this query just yet, because it will
remove the "Compound" field, and any form, query, property or VBA code
currently using this field will fail.
If you have Access 2003, run the Object Dependencies feature for this table
and check whether any of these dependent objects are specifically using the
Compound field. If they are, you will need to alter these so that they use
the new fields instead. If you don't have Access 2003, you may purchase a
tool, such as Speed Ferret or FMS Total Access Analyzer to search for these
items for you. Short of that, I would rename this field temporarily to
"Compound_Old," search through the VBA code for the word "Compound," and if
I found any, make changes to use the new fields, and test the entire
application and see whether anything breaks. Whatever breaks needs to be
fixed so that it uses the new fields.
When you are sure that nothing else is dependent on the original field, back
up the database, rename the altered Compound_Old field back to Compound,
then run the qryDropTblCensusColumn query to get rid of this field.
Compact/repair the database and you're done.
I agree. Good thing you're doing it now instead of later when you have 50
more queries, forms, and modules dependent on this table's original
structure. Good luck.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)