How to autofill in a table

G

GGD

For example, there are some fields in a Human Resources table, like 'name',
'sex', 'age' and so on. Now I input a person's name in the salary table
which also contains 'name', 'sex' and 'age' fields. I want Access autofill
his/her sex, age information when I input his/her name, how can I do? By
the way, I use Access2003.
Thanks!
 
A

Allen Browne

Suggestions:

1. Storing age
Don't have an Age field! Instead, use a BirthDate (Date/Time) or BirthYear
(Number) field. The age changes all the time, so if you have a few hundred
people, storing the age means your stored data is wrong again almost every
day. You can calculate the age as needed from the birth data. Post a reply
if you need more details of that.

2. Storing gender
If you have a Title field (entries such as Mr/Ms/Dr/Prof/Rev/...), you can
use the AfterUpdate event procedure of this control on your form to have a
guess at the gender and assign a value to your Sex field. This only works
for some titles though.

If you want to do it by looking at the person's name, you would need to
teach it how. That would mean creating a table of common first names, with
the most likely gender to guess. Again, this only works with some names.

3. Name field
Hopefully you don't really have a field called Name. Almost everything in
Access has a Name property, so Access will misunderstand it, e.g. thinking
you are talking about the name of the form instead of the contents of the
text box called Name.

In any case, you really need to break the name down into its parts, which
makes it much more efficient for searching and sorting. Using separate
fields for Surname and FirstName would be minimal.
 
G

GGD

Thanks very much for your help!

I means, the human resources tables have already contained all the data of
everyone, including his/her name, gender, birthday and so on. These records
are already there.
And now, I want Access autofill someone's gender, birthday when I input
his/her name in another table ( this table also contains gender, birthday
.... fields ). Can it autofill these fields associated the person by his/her
name? Suppose there are no same names in HR tables.
Thanks again!
 
D

Douglas J. Steele

In addition to Allen's spot-on advice, be aware that you shouldn't store the
sex, name and age fields in the Salary table. All that should be there is a
foreign key pointing to the appropriate entry in the Person table. Create a
query that joins the two tables when you need the additional information.

Access is a relational database system: use it relationally!
 
A

Allen Browne

So you already have a Staff table with one record per person and a StaffID
primary key, and you are now creating a Salary table so that one staff
member can have multiple salary entries over time.

The Salary table will have a StaffID field that relates to the Staff table's
StaffID. The Salary table should not have any of the other fields from the
Staff table - not the name, age, etc.

Instead you can create a query that joins the 2 tables. In the query output,
include all the fields from the Salary table, and the ones you need to see
from the Staff table. This enables you to see any of the staff fields you
want, without duplicating them in the Salary table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top