Immediately after posting this it occurred to me that I'm wanting to do
something I should really never do, i.e. duplicate information in my
database. So let me explain the whole situation (why didn't I do that to
begin with?) and see if you have any ideas.
In addition to the table tIncidentFromForms I also have a table
tOrgDistrict. That table is indexed on a field called CountyDistrictNum.
I need to be able to create a relationship between tIncidentFromForms and
tOrgDistrict because I need to run a query that will grab information
from both tables. If I can create the field CountyDistrictNum in
tIncidentFromForms then the relationship is easy to establish and my
query runs fine. Unfortunately, there is no other field in tOrgDistrict
that is unique so that is what I have to base this relationship on.
Knowing that, how can I best go about creating this relationship so that
I can run my query?
My query is as follows (if it's important to know that in figuring this
all out):
SELECT tIncidentFromForms.DistrictName,
tOrgDistrict.SuperintendentFullName, tOrgDistrict.StreetAddress,
tOrgDistrict.City, tOrgDistrict.State, tOrgDistrict.ZipCode,
tIncidentFromForms.CampusName, tIncidentFromForms.Involved1FirstName,
tIncidentFromForms.Involved1LastName,
tIncidentFromForms.Involved2FirstName,
tIncidentFromForms.Involved2LastName, tIncidentFromForms.Administration,
tIncidentFromForms.Year, tIncidentFromForms.Grade,
tIncidentFromForms.TestType, tIncidentFromForms.Subject,
tIncidentFromForms.Description, tIncidentFromForms.DTCFullName
FROM tOrgDistrict RIGHT JOIN tIncidentFromForms ON
tOrgDistrict.CountyDistrictNum = tIncidentFromForms.CountyDistrictNum
ORDER BY tIncidentFromForms.DistrictName;
Tom Ellison said:
Dear Brian:
For almost all purposes, Bruce is right on.
There are two exceptions: You want a snapshot in time that shows what
was in CDC1 and CDC2 at one time, even though they may have changed.
Then you must concatenate and save them now, before they change again.
It is unusual, but not unheard of, to need this.
The other exception is that you need to sort the table on this.
Assuming they're both strings, you could just sort on each in order and
get that effect. But if they are of different types, and you want them
sorted by their combined string value, then the sort may not work the
same on them separately.
Again, you could do this dyanamically in the query in the sorting of
that query without sorting. But, in even rarer instances, you may need
an index on the combination for performance purposes.
In this case, you should switch from Jet to MSDE where you can create a
calculated column and where you can build an index on that. When the
value of CDC1 or CDC2, the calculated column would instantly and
automatically change as well, and the index be modified accordingly.
Except for the first case above, there are better ways to do this. What
you suggest will not track any changes to the CDC1 and CDC2 columns. If
you want it to track, choose another way.
Tom Ellison
Best way is not to do it. Concatenate on the fly in a form, report, or
query when you need to view the combined result.
I have a table (tIncidentFromForms) and I'm dealing with 3 fields
within that form: CDC1, CDC2, and CountyDistrictNum. CDC1 and CDC2
both have data in them and I would like to concatenate the data in both
of those fields and put it in CountyDistrictNum. Essentially I want:
[tIncidentFromForms]![CountyDistrictNum] = [tIncidentFromForms]![CDC1]
& [tIncidentFromForms]![CDC2]
for every record that is in tIncidentFromForms.
What is the best way for me to go about this? A macro? A module?
I've gone in and done it all by hand before, but I know there has to
be an easier way.
-Brian Beck