hi
Florin,
for reference, here is how you said the codm field breaks down:
202012011 is coding for
20 - specialty
2 - year of study
01 - matter order number
2011 - year of study
BACKUP your database. Always do this before running any update queries. Open database.
1. Go to the design view of
materii
2. Change the Data Type of
codm to
Text or Short Text, Field Size=
9 (bottom pane)
3. Add these 4 fields to your table to keep track of the codm parts (OR WHATEVER YOU WANT TO CALL THEM -- KEEP NAMES THE SAME AS THEY'RE CALLED IN OTHER PLACES. DATA TYPE IN OTHER PLACES SHOULD MATCH THESE):
- SpecialtyNbr, Number, Field Size = Integer, Default Value is nothing (delete 0 if Access adds it)
- StudyYr, Number, Field Size = Integer, Default Value is nothing (delete 0 if Access adds it)
- MatterNbr, Number, Field Size = Integer, Default Value is nothing (delete 0 if Access adds it)
- Yr, Number, Field Size = Integer, Default Value is nothing (delete 0 if Access adds it)
Make an Update Query to fill the new fields
Create a new query based on the materii table and go to the design view
- Put codm on the grid in the Field cell
- Criteria --> Is Not Null
you said,
specialty which can be from 1 to 30 (ex. 9,17,24 ...)
Add a calculated column:
- Field --> LenCodm: Len([codm])
Look at the data. Is codm always 8 or 9?
it should be 8 if Specialty number is less than 10, or 9 if not
So far, this is still a Select query to show data from your table. Now go back to the Design View
We don't need the LenCodm field so you can delete it.
Change the query to an Update query. On the Design ribbon, in the Query Type group, click on Update
the grid will change. Now you have a row called Update To
Add this information to the grid:
Field --> SpecialtyNbr
Update To --> IIf( Len([codm])=8, Left([codm],1), Left([codm],2) )
Field --> StudyYr
Update To --> Mid( [codm], IIf(Len([codm])=8, 2, 3),1)
continue this pattern with the new MatterNbr and Yr fields. Even what is being calculated in the UpdateTo cell is text, and the fields we're updating are numbers, Access will implicitly convert the data type and get it right
Save this query as -->
qUp_materii
To run and make the changes to your table, click the
! Run button on the
Design ribbon when you are looking at the design view of the query
~~~~~~~~~~~~~~~~ unrelated:
Change the NAME of the Note table since "note" is a reserved word. You can look up bad names and reserves words here:
allenbrowne.com/AppIssueBadWord.html
Perhaps call it Notes. I also see you have 3 fields in the Notes table that are also reserved words: Name, Type and Data
There might be other reserved words too. I didn't look. On forms and reports, you'll also have to change
- the RecordSource
- the Control Source and Name (to match Control Source) properties of controls based on this table.