Richard:
I'd strongly recommend you follow Doug's advice and split the value over
three columns, AssetType, DistrictLocation and AssetNumber say, the first two
being of text data type, the last an integer number data type.
DistictLocation could be a number data type, but its really more of a code
than a number per se, so I'd favour using a text data type.
By adding these columns to the existing table into which the Excel data has
been imported, you can then fill the three new columns with an 'update' query:
UPDATE Assets
SET AssetType = LEFT(AssetCode,1),
DistrictLocation = MID(AssetCode,2,3),
AssetNumber = VAL(MID(AssetCode,5));
To compute the values for new records set the DefaultValue properties of the
AssetType and DistrictLocation columns to "F" and "640" respectively, and in
the BeforeInsert event procedure of your data entry form put:
Dim strCriteria As String
strCriteria = "AssetType = """ & Me.AssetType & _
""" And DistrictLocation = """ & Me.DistrictLocation & """"
Me.AssetNumber = Nz(DMax("AssetNumber", "Assets", strCriteria),0)+1
For the above examples I've assumed the table is named Assets and the
existing structured column is named AssetCode.
One thing to be aware of is that if in a multi-user environment two users
are adding new records simultaneously each will get the same next number, so
you should index the AssetNumber column uniquely (no duplicates). In the
event of a conflict the first user to save their record would be successful,
others would raise an index violation error.
To ensure data integrity you should ideally also have tables AssetTypes and
DistrictLocations, each with one column. If, as you seem to be saying, only
fixed assets with a district location value of 640 are being recorded then
these tables will have only one row each. By enforcing referential integrity
in the relationships between these tables and Assets the integrity of the
data in the AssetType and DistrictLocation columns in Assets is protected.
The AssetTypes and DistrictLocations columns in Assets are of course not
actually necessary in this scenario as the values can be obtained from the
other tables, but having them as foreign key columns in Assets does leave
scope for possible future expansion to include other asset types and/or
district locations; which is why I've included the criterion for the DMax
function call above; though if you do include other asset types/district
locations with independent numbering you'd need to change the unique index
from one on AssetNumber only to one on all three columns.
To show the full structured asset code in a form or report concatenate the
values of the three columns in an unbound text box with a ControlSource
property of:
=[AssetType] & [DistrictLocation] & Format([AssetNumber],"00000")
Or you can use the same expression in a computed column in a query.
Ken Sheridan
Stafford, England
Richard said:
Cilf,
What i'm thinking is everytime a "new record" is created then a new number
is assigned for example F640XXXX1 F640XXXX2 and so on