Copying a field of a specific record, withing a table

J

Jon

Please excuse the simplicity of this question, I am an
utter newbie to Access, and I scarcely understand most of
what the posts on this forum are about. So when I
searched the forums for an answer to my probably
exceptionally simple question, I didn't even know what I
was looking at.

I am using Access to keep track of pedigrees in an animal
colony. The animals are indicated by number, and I keep
track of parental genotypes to select who breeds with
who. I need to be able to trace this over many
generations to watch for errors or unexpected gene
transmission. When I enter a new animal into the list, I
enter the number references for Mom and Dad. I want the
software to go back to the record for Mom and Dad
(respectively) and fetch the genotypes for each of those
animals and copy them into new field "Dad genotype"
and "Mom genotype".

Brief rewording:
Each animal has (among others)
fields "genotype", "mom", "mom genotype", "dad", and "dad
genotype". The numbers entered in the fields "mom"
and "dad" refer to another record (animal). When I enter
a new mouse, I input the numbers of its mom and dad. I
want Access to fetch the "genotype" field from the record
referenced by the "dad" field and put that in the "dad
genotype" field of the new record. Same for the "mom"
field.

I hope all that makes sense...Like I said, I'm a newbie
here. Any help in the form of newbie-oriented websites,
hints, etc. would be very helpful.
 
L

Larry Linson

I'd suggest you have an animals table with fields for the individual
animals, their genotype, and a key field that identfies the Mom and Dad
records in that same table -- then fetch the appropriate genotypes via
querying, self-joining the same table multiple times in the query, depending
on how many generations back you want to go. It will make your life easier
"down the road" if you store your information in that normalized form,
rather than the unnormalized form you showed.

Larry Linson
Microsoft Access MVP
 
L

Larry Daugherty

Jon

The solution to your problem is an example showing how to provide
recursion within a single table. At the simplest level you need a single
table and a single form. You will probably later decide you need some
reports but that wasn't in your post...

Open a new table in design mode and include fields for all of the
following: MyID, type of Autonumber, this is the recordID and is not to be
displayed on your forms and reports; Gender, type is text, set the character
count to 1 (M or F); "genotype", MomID, type is long integer number,, "mom
genotype", DadID, type is long integer number, and "dad genotype", Note,
type of Text. I recommend making the field type = Text for all of the
fields you've already named, even if it looks like numbers.

The field MyID is an autonumber field that provides unique record ID
numbers and should not be used for anything that a human needs to read or
understand. The reason for that is that the number will start out as a nice
numerical sequence but will eventually develop gaps. The gaps won't
interfere with program operation but can drive people crazy!

Save the table with a name that has meaning to you. I'd use something
creative like "tblMmouse" but you might have better ideas.

Your first generation won't have MomID and DadID values but you can
enter the rest of the information by hand and explain things in the Notes
field as necessary.

Once you have your table named and saved you can select it in the
Database\Tables window and then click the Autoform Wizard icon. Answer the
wizard questions until it gives you a form. Note that this is a process you
can repeat many times. If you generate an ugly and useless form, simply
delete it and start over. If you're undecided, give it a name and save it
and generate the next one until you get a form you're sure you want to work
with. You should end up with a form that displays two controls for each
field in tblMouse: A label and a TextBox control.

Open your form in design view and click the Properties on. Selecting a
control on the form will cause its properties to be displayed in the
Properties dialogue. You can change the labels to more meaningful text or
leave them as is for a while. Same goes for the name property of each
textbox control. I suggest you go all the way through the whole process
from beginning to end before you do much name changing. If the toolbox
isn't showing, click View|Toolbox. On the toolbox, make sure that wizards
(commandbar with a baton and stars) is turned on.

Click View|Form Header and Footer to get a header. What we're going to
do next is put a couple of comboboxes in the header area to get the
information from each of the parents and load it into the form. Click and
release the combobox tool, move the cursor into the header area and draw a
combobox about the same size as a textbox in the form below leaving enough
space to the left for the wizard to insert a label. Trial and error is OK.
As soon as you release the mouse button the wizard will give you three
choices: choose the first one " ... look up values ..". The wizard will
ask what fields you want for your combobox. You want MyID, Gender and
Genotype and be sure that the checkbox "Hide Key" is checked.. Click Next
and tell it to remember the values. Click Next. The name you want to use
is "cboGetMom" without the quotes. Do all of the above steps exactly the
same except that you want the next combobox to be on the right side of the
header area and the name of the combobox will be "cboGetDad".

Click in the label of the first combobox, delete what's there and type:
Get Mom. Open the properties for cboGetMom. Click on the Data tab. Click
to the right of the Row Source textbox and doubleclick on the ellipsis (...)
when it appears. That will open the QBE grid which gives a graphic
representation of the query on which the combobox is based. In the criteria
line in the column for Gender type type following: Like "F" or "f" Click
the X in the upper right of the QBE grid form and tell it you want to save
changes and close the QBE grid. If you exit in such a way that it asks you
to give your query a name, click cancel. You don't want to name the query
and put it in the query window!

Now do all of the same things for the combobox to the right except
change the label to read "Get Dad". For the criteria line in the Gender
column in the QBE grid type:
Like "M" or "m" .

The last thing we have to do to get a working prototype is to put some
code into the AfterUpdate events of the two comboboxes. Just an aside here
so that when you discover on your own what I'm about to tell you it won't be
a rude shock. In the properties for the comboboxez you'll want to set the
Bound Column property to "1" (no quotes). In that case it means the first
column. However, when we refer to the first column in code it will be
..column(0)! That's just the way it is.

Note that the names I use may or may not agree with names you're using.
I'll use names that should indicate the content and you can change them to
work with your application. In Design mode, select cboGetMom and in the
Property form click the Event tab. Doubleclick the ellipsis to the far
right of the AfterUpdate event. That will open the Visual Basic Editor in a
subroutine named "cboGetMom_AfterUpdate".. At some early time you'll want
to add some error handling code. Hit Enter a couple of times and type:

Me!MomId = Me!cboGetMom.column(0)
Me!MomGenotype = Me!cboGetMom.column(1)


At the top of the Design window, click Debug and choose Compile and save
all.

Now do the same for cboGetDad changing the names appropriately. A trick
you can use is to copy the two lines of code above and paste them into
cboGetDad_AfterUpdate then find and replace on Mom -> Dad.

This new leaves you the task of manual entry on a couple of textboxes
but the overall application should work pretty well.

While I don't guarantee success using the steps above I do believe I've
started you in a direction to do what you want. Good Luck!

hth
 

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