Writing data to multiple, related tables

G

Guest

I have a very large database to which I need to add new data on a regular
base. Because of its size, I have split the database into two and linked
them by a primary key. The primary key in both forms is a route number and
year combination. I am creating a form for data entry which will contain
multiple tabs, because of the size of the database. The primary key is
entered by the user during data entry. My question is: In Access 2000 or
2003, is there a way to have the form write the primary key to both of the
underlying tables? I've tried adding both fields (from each table) to the
"Control Source" in the properties, but now it doesn't write data to either
table.

Jeff
 
S

strive4peace

Hi Jeff,

where is the data going to come from? Do you mean that you want the
data transferred to subforms from the main form? You can set the
LinkMasterFields and LinkChildFields properties of the subform control
and this will happen automatically

~~~
each form/subform should be based on just one table ... you will need a
main form to for the main table and subforms to display and edit
information in each of the related tables

Create the main form and forms that will be used as subforms -- make
sure to put the ID fields on them

to put a subform on a main form:
create a subform control on you main form using the toolbox (Cancel the
wizard if it pops up and fill properties manually)

Then, from the design view of the main form

1. turn on the properties window
(r-click anywhere and choose Properties from the shortcut menu)

2. click ONE time on the subform control if it is not already selected

3. click on the DATA tab of the Properties window

SourceObject --> drop list and choose the name of the form you will use
as a subform

LinkMasterFields --> MainID
LinkChildFields --> MainID

If you have multiple fields, delimit the list with semi-colon

LinkMasterFields --> MainID;maincontrolname
LinkChildFields --> MainID;childcontrolname

where MainID is an autonumber field (usually) in the parent table and a
Long Integer field in the child table

the link field properties actually use controls, not fields -- so the
controls you reference must be ON each of the respective forms and the
NAME property is what you need to reference -- if a control is bound, I
usually make the Name of the control the same as the ControlSource (what
is in it)

It is common to set the Visible property to No for the control(s) used
in LinkChildFields

then, while still on the subform control, click the ALL tab -- change
the Name property to match the SourceObject property (minus Form. in the
beginning if Access puts it there)

*** Difference between Subform Control and Subform ***

The first click on a subform control puts handles* around the subform
object.
*black squares in the corners and the middle of each size -- resizing
handles

The subform object has properties such as

Name
SourceObject
LinkMasterFields
LinkChildFields
Visible
Locked
Left
Top
Width
Height

the subform control is just a container for the subform.

the subform itself is an independent form -- you can open it directly
from the database window and it has the same properties of the main
form. It is only called a subform because of the way it is being used.

To summarize, when you are in the design view of the main form, the
first click on the subform is the subform control -- you will see the
handles around the edges -- and the second click gets you INTO it -- you
will see a black square where the rulers intersect in the upper left of
the "form" you are "in" (and this is the same as if you went to the
design directly)

me.subform.controlname --> the subform control
me.subform.controlname.form --> the form inside the subform control

Personally, I edit subforms directly, not from inside the main form -- I
have had trouble with Access putting property changes in the wrong place
for RowSources and RecordSource. Since it happens there occassionally,
for major changes, I go to the design view of the "sub"form directly
from the databse window when the main form is closed.
the subform itself is an independent form -- you can open it directly
from the database window and it has the same properties of the main
form. It is only called a subform because of the way it is being used.

To summarize, when you are in the design view of the main form, the
first click on the subform is the subform control -- you will see the
handles around the edges -- and the second click gets you INTO it -- you
will see a black square where the rulers intersect in the upper left of
the "form" you are "in" (and this is the same as if you went to the
design directly)

me.subform.controlname --> the subform control
me.subform.controlname.form --> the form inside the subform control


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

Crystal:

Thanks for the reply. The data for the form will be entered into the forms.
That is, until it is entered on the forms I am trying to create, there is no
electronic version of the data. I want to be able to enter the primary key
only once and have it written to both of the underlying tables. For example.
If I am entering data from a survey, I might assign it a primary key of
23-2007, indicating it was the 23 survey processed in 2007. Data from this
survey will be added to two different tables. Rather than enter the primary
key twice, once for each table, I want to enter it once and have Access add
it to both tables. I hope that makes sense. It is likely not possible,
though, given the responses I received to my other post.

Thanks again and let me know if you think of some way to do this.

Jeff--
 
S

strive4peace

linking main and subforms
---


Hi Jeff,

enter the pk (primary key) into a control on the the main form (or it
can also be a generated autonumber)

use this control name for the LinkMasterFields property of the subform
control that you want the info transferred to

then, on the subform, make sure this field is THERE as a control (it can
be hidden) and, once again, use the NAME of the control for the
LinkchildFields property of the subform control

data will be filtered for the link fields and automatically filled when
new records are created

for better understanding, download and read this:

Access Basics
http://allenbrowne.com/tips.html
Tips for Casual Users
Access Basics: free tutorial - Word document by Crystal (Access MVP)

This 30-page training tutorial will orient you toward the core concepts
of Microsoft Access -- good foundation for learning programming



Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

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