Auto-Poulate a Value in a Table

K

Kerensky18

Hello Again;

I have another issue that I can't figure out. I'm designing a Insurance
database for class and am having issues with two tables.

The two tables are Policy and Additional Insured.

Policy is tied to Additional insured via policy ID.

What I would like to happen is the user clicks on a button in Policy(form)
called Add Additional Insured. I want this button to open up the Additional
Insured(form) to a blank record and auto-populate the Policy ID #. Is it
possible to do this?
 
J

Jeff Boyce

It sounds like you are saying you want an empty (?dummy?) record created in
table2 when you create a new record in table1. Why?

In Access, you typically would not need or want to create a new record in
any table until you had data to put in it.

Also, in Access, you would typically handle creating one/more related
records in a "child" table (your [AdditionalInsured]) by using a main form
(displays the [Policy] info)/sub-form (displays any/all [AdditionalInsured]
info) construction. This way, Access would handle adding the necessary
[PolicyID] to the child table, but only when you need to add a record.

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
K

Kerensky18

I will try to clarify further... I want the policy number to transfer to the
new record instead of the records policy number being the default NULL.

For instance the policy number is 5, I click add additional insured button,
brings me to a blank form to update the table but with the policy field
already having the value of 5.

Jeff Boyce said:
It sounds like you are saying you want an empty (?dummy?) record created in
table2 when you create a new record in table1. Why?

In Access, you typically would not need or want to create a new record in
any table until you had data to put in it.

Also, in Access, you would typically handle creating one/more related
records in a "child" table (your [AdditionalInsured]) by using a main form
(displays the [Policy] info)/sub-form (displays any/all [AdditionalInsured]
info) construction. This way, Access would handle adding the necessary
[PolicyID] to the child table, but only when you need to add a record.

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Kerensky18 said:
Hello Again;

I have another issue that I can't figure out. I'm designing a Insurance
database for class and am having issues with two tables.

The two tables are Policy and Additional Insured.

Policy is tied to Additional insured via policy ID.

What I would like to happen is the user clicks on a button in Policy(form)
called Add Additional Insured. I want this button to open up the Additional
Insured(form) to a blank record and auto-populate the Policy ID #. Is it
possible to do this?
 
J

Jeff Boyce

Again, you are describing "how" ("I click... brings me to ...").

Re-read my suggestion about using a main form/sub-form construction. Access
will take care of copying the main form's primary key value into the
sub-form's foreign key.

While it is possible to do what you are describing, exactly as you are
describing, it is most certainly harder than the above method. After all,
you can drive nails with a chain saw, but it isn't necessarily a good use of
the tool...<g>

Regards

Jeff Boyce
Microsoft Office/Access MVP

Kerensky18 said:
I will try to clarify further... I want the policy number to transfer to
the
new record instead of the records policy number being the default NULL.

For instance the policy number is 5, I click add additional insured
button,
brings me to a blank form to update the table but with the policy field
already having the value of 5.

Jeff Boyce said:
It sounds like you are saying you want an empty (?dummy?) record created
in
table2 when you create a new record in table1. Why?

In Access, you typically would not need or want to create a new record in
any table until you had data to put in it.

Also, in Access, you would typically handle creating one/more related
records in a "child" table (your [AdditionalInsured]) by using a main
form
(displays the [Policy] info)/sub-form (displays any/all
[AdditionalInsured]
info) construction. This way, Access would handle adding the necessary
[PolicyID] to the child table, but only when you need to add a record.

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Kerensky18 said:
Hello Again;

I have another issue that I can't figure out. I'm designing a Insurance
database for class and am having issues with two tables.

The two tables are Policy and Additional Insured.

Policy is tied to Additional insured via policy ID.

What I would like to happen is the user clicks on a button in
Policy(form)
called Add Additional Insured. I want this button to open up the Additional
Insured(form) to a blank record and auto-populate the Policy ID #. Is
it
possible to do this?
 
K

Kerensky18

Ok I've put a subform into the main form but it still dosnt transfer down the
policy number.. Is there a property I'm missing to do this?

Jason

Jeff Boyce said:
Again, you are describing "how" ("I click... brings me to ...").

Re-read my suggestion about using a main form/sub-form construction. Access
will take care of copying the main form's primary key value into the
sub-form's foreign key.

While it is possible to do what you are describing, exactly as you are
describing, it is most certainly harder than the above method. After all,
you can drive nails with a chain saw, but it isn't necessarily a good use of
the tool...<g>

Regards

Jeff Boyce
Microsoft Office/Access MVP

Kerensky18 said:
I will try to clarify further... I want the policy number to transfer to
the
new record instead of the records policy number being the default NULL.

For instance the policy number is 5, I click add additional insured
button,
brings me to a blank form to update the table but with the policy field
already having the value of 5.

Jeff Boyce said:
It sounds like you are saying you want an empty (?dummy?) record created
in
table2 when you create a new record in table1. Why?

In Access, you typically would not need or want to create a new record in
any table until you had data to put in it.

Also, in Access, you would typically handle creating one/more related
records in a "child" table (your [AdditionalInsured]) by using a main
form
(displays the [Policy] info)/sub-form (displays any/all
[AdditionalInsured]
info) construction. This way, Access would handle adding the necessary
[PolicyID] to the child table, but only when you need to add a record.

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Hello Again;

I have another issue that I can't figure out. I'm designing a Insurance
database for class and am having issues with two tables.

The two tables are Policy and Additional Insured.

Policy is tied to Additional insured via policy ID.

What I would like to happen is the user clicks on a button in
Policy(form)
called Add Additional Insured. I want this button to open up the
Additional
Insured(form) to a blank record and auto-populate the Policy ID #. Is
it
possible to do this?
 
K

Kerensky18

Nevermind I got it to work. Thank you for your help

Kerensky18 said:
Ok I've put a subform into the main form but it still dosnt transfer down the
policy number.. Is there a property I'm missing to do this?

Jason

Jeff Boyce said:
Again, you are describing "how" ("I click... brings me to ...").

Re-read my suggestion about using a main form/sub-form construction. Access
will take care of copying the main form's primary key value into the
sub-form's foreign key.

While it is possible to do what you are describing, exactly as you are
describing, it is most certainly harder than the above method. After all,
you can drive nails with a chain saw, but it isn't necessarily a good use of
the tool...<g>

Regards

Jeff Boyce
Microsoft Office/Access MVP

Kerensky18 said:
I will try to clarify further... I want the policy number to transfer to
the
new record instead of the records policy number being the default NULL.

For instance the policy number is 5, I click add additional insured
button,
brings me to a blank form to update the table but with the policy field
already having the value of 5.

:

It sounds like you are saying you want an empty (?dummy?) record created
in
table2 when you create a new record in table1. Why?

In Access, you typically would not need or want to create a new record in
any table until you had data to put in it.

Also, in Access, you would typically handle creating one/more related
records in a "child" table (your [AdditionalInsured]) by using a main
form
(displays the [Policy] info)/sub-form (displays any/all
[AdditionalInsured]
info) construction. This way, Access would handle adding the necessary
[PolicyID] to the child table, but only when you need to add a record.

Good luck!

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Hello Again;

I have another issue that I can't figure out. I'm designing a Insurance
database for class and am having issues with two tables.

The two tables are Policy and Additional Insured.

Policy is tied to Additional insured via policy ID.

What I would like to happen is the user clicks on a button in
Policy(form)
called Add Additional Insured. I want this button to open up the
Additional
Insured(form) to a blank record and auto-populate the Policy ID #. Is
it
possible to do this?
 
P

Pat Hartman

The easiest way to pass the PK value to a popup form is with the OpenArgs
argument of the OpenForm method. Then in the BeforeInsert event of the
popup form, you use the value in OpenArgs to populate the foreign key to
link the records.

Me.parentKeyfield = Me.OpenArgs

I use the BeforeInsert event because I don't want to dirty the form before
the users do since that just causes them confusion when they try to close an
incomplete form that they never typed anything into or I have to add extra
code to trap these errors. KISS is my motto. As you seem to have
discovered, Access takes care of setting the FK value for you when you use a
subform with the master/child links properly defined.
 

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

Similar Threads


Top