In the SubAssemblies table use separate columns for the ID# and the letter
suffix. It’s a trivial task to concatenate the values when required. Make
both columns the composite primary key of the table. Consequently each
sub-assembly row will have an ID# which references its parent row in the
Assemblies table.
In a form bound to the SubAssemblies table you can compute the suffix in the
AfterUpdate event procedure of the ID# control (you'll have to use another
event, however, if the sub-assemblies are being entered via a linked subform
in which the ID# value is automatically inserted; the subform's Current event
procedure would probably do. In either event the code would be as follows:
Dim varLastChr As Variant
Dim strCriteria As String
' look up last suffix, if any, for current ID#
strCriteria = "[ID#] = " & Me.[ID#]
varLastChr = DMax("Suffix", "SubAssemblies", strCriteria)
' get ASCII code of last letter, add 1 and then
' get letter for that ASCII value
Me.Suffix = Chr(Asc(Nz(varLastChr, Chr(64)))+1)
'A' is Chr(65) so if no row yet exists for the ID# 1 (the DMax function
returns a Null) the ASCII code of Chr(64) is obtained and 1 added to give 'A'
as the first suffix.
The above assumes that the ID# column is a number data type. If its text
data type use:
strCriteria = "[ID#] = """ & Me.[ID#] & """"
What do you mean by "All data fields are the same but some other data needs
to be updated"? If you are duplicating non-key values in the two tables then
that introduces redundancy and gives rise to the risk of inconsistent data.
Only the ID# keys should have common values in both tables. Other columns
should represent attribute types specific to the assembly or sub-assembly.
You might have columns in SubAssemblies with the same names as those in
Assemblies, but only if the values for those columns in the former will
differ from those in the latter. It’s a question of what's known in the
jargon as 'functional dependency'. An analogous situation can be found in
the sample Northwind database where both the Products and OrderDetails tables
have UnitPrice columns. This is because the unit price of a product in the
latter is the price at the time of the order, whereas that in the former is
the current price, i.e. each is functionally dependent on the key of its
table.
Ken Sheridan
Stafford, England
C Parkins said:
I am working on an inventory project with parent data that is used to create
child data fields. I would like to take the parent ID# ( a five digit number)
and add a alphabetic suffix ( A for the first sub part, B for the second...)
While still maintaining the original ID #. Currently the parent assembly is
in one table and the sub assembly data is created and placed into a second
table. All data fields are the same but some other data needs to be updated.
what is the best way to do this.